[PATCH] D34329: [GSoC] Clang AST diffing

2017-06-20 Thread Johannes Altmanninger via Phabricator via cfe-commits
johannes updated this revision to Diff 103320.
johannes added a comment.

- Fix a bug in getSimilarity()
- Change terminology: `label` -> `value`
- Define SNodeId: Now it cannot be implicitly constructed from an int, however 
it can be converted to int. Still feels a bit weird
- Fix some issues with SNodeId
- Rewrite the computation of leftmost descendants in subtrees.


https://reviews.llvm.org/D34329

Files:
  include/clang/Tooling/ASTDiff/ASTDiff.h
  lib/Tooling/ASTDiff/ASTDiff.cpp
  lib/Tooling/ASTDiff/CMakeLists.txt
  lib/Tooling/CMakeLists.txt
  test/Tooling/clang-diff-basic.cpp
  tools/CMakeLists.txt
  tools/clang-diff/CMakeLists.txt
  tools/clang-diff/ClangDiff.cpp

Index: tools/clang-diff/ClangDiff.cpp
===
--- /dev/null
+++ tools/clang-diff/ClangDiff.cpp
@@ -0,0 +1,110 @@
+//===- ClangDiff.cpp - compare source files by AST nodes --*- C++ -*- -===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// This file implements a tool for syntax tree based comparison using
+// Tooling/ASTDiff.
+//
+//===--===//
+
+#include "clang/Tooling/ASTDiff/ASTDiff.h"
+#include "clang/Tooling/CommonOptionsParser.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/Support/CommandLine.h"
+
+using namespace llvm;
+using namespace clang;
+using namespace tooling;
+
+static cl::OptionCategory ClangDiffCategory("clang-diff options");
+
+static cl::opt
+DumpAST("ast-dump",
+cl::desc("Print the internal representation of the AST as JSON."),
+cl::init(false), cl::cat(ClangDiffCategory));
+
+static cl::opt NoCompilationDatabase(
+"no-compilation-database",
+cl::desc(
+"Do not attempt to load build settigns from a compilation database"),
+cl::init(false), cl::cat(ClangDiffCategory));
+
+static cl::opt SourcePath(cl::Positional, cl::desc(""),
+   cl::Required,
+   cl::cat(ClangDiffCategory));
+
+static cl::opt DestinationPath(cl::Positional,
+cl::desc(""),
+cl::Optional,
+cl::cat(ClangDiffCategory));
+
+static std::unique_ptr getAST(const StringRef Filename) {
+  std::string ErrorMessage;
+  std::unique_ptr Compilations;
+  if (!NoCompilationDatabase)
+Compilations =
+CompilationDatabase::autoDetectFromSource(Filename, ErrorMessage);
+  if (!Compilations) {
+if (!NoCompilationDatabase)
+  llvm::errs()
+  << "Error while trying to load a compilation database, running "
+ "without flags.\n"
+  << ErrorMessage;
+Compilations.reset(
+new FixedCompilationDatabase(".", std::vector()));
+  }
+  std::array Files = {{Filename}};
+  ClangTool Tool(*Compilations, Files);
+  std::vector ASTs;
+  Tool.buildASTs(ASTs);
+  if (ASTs.size() != Files.size())
+return nullptr;
+  return std::move(ASTs[0]);
+}
+
+int main(int argc, const char **argv) {
+  cl::HideUnrelatedOptions(ClangDiffCategory);
+  if (!cl::ParseCommandLineOptions(argc, argv)) {
+cl::PrintOptionValues();
+return 1;
+  }
+
+  if (DumpAST) {
+if (!DestinationPath.empty()) {
+  llvm::errs() << "Error: Please specify exactly one filename.\n";
+  return 1;
+}
+std::unique_ptr AST = getAST(SourcePath);
+if (!AST)
+  return 1;
+clang::diff::TreeRoot Tree(AST->getASTContext());
+Tree.printAsJson();
+return 0;
+  }
+
+  if (DestinationPath.empty()) {
+llvm::errs() << "Error: Exactly two paths are required.\n";
+return 1;
+  }
+
+  std::unique_ptr Src = getAST(SourcePath);
+  std::unique_ptr Dst = getAST(DestinationPath);
+  if (!Src || !Dst)
+return 1;
+
+  diff::TreeRoot T1(Src->getASTContext());
+  diff::TreeRoot T2(Dst->getASTContext());
+  diff::ASTDiff DiffTool(T1, T2);
+  diff::Mapping M = DiffTool.computeMapping();
+  M.printMapping();
+  auto Changes = DiffTool.computeChanges(M);
+  for (const auto  : Changes)
+DiffTool.printChange(C);
+
+  return 0;
+}
Index: tools/clang-diff/CMakeLists.txt
===
--- /dev/null
+++ tools/clang-diff/CMakeLists.txt
@@ -0,0 +1,13 @@
+set(LLVM_LINK_COMPONENTS
+  Support
+  )
+
+add_clang_executable(clang-diff
+  ClangDiff.cpp
+  )
+
+target_link_libraries(clang-diff
+  clangFrontend
+  clangTooling
+  clangToolingASTDiff
+  )
Index: tools/CMakeLists.txt
===
--- tools/CMakeLists.txt
+++ tools/CMakeLists.txt
@@ -2,6 +2,7 @@
 
 add_clang_subdirectory(diagtool)
 

r305878 - Changed wording in comment

2017-06-20 Thread Raphael Isemann via cfe-commits
Author: teemperor
Date: Wed Jun 21 00:41:39 2017
New Revision: 305878

URL: http://llvm.org/viewvc/llvm-project?rev=305878=rev
Log:
Changed wording in comment

Modified:
cfe/trunk/lib/Analysis/CloneDetection.cpp

Modified: cfe/trunk/lib/Analysis/CloneDetection.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CloneDetection.cpp?rev=305878=305877=305878=diff
==
--- cfe/trunk/lib/Analysis/CloneDetection.cpp (original)
+++ cfe/trunk/lib/Analysis/CloneDetection.cpp Wed Jun 21 00:41:39 2017
@@ -635,8 +635,7 @@ void CloneConstraint::splitCloneGroups(
 if (Indexes[j])
   continue;
 
-// If a following StmtSequence belongs to our CloneGroup, we add it to
-// it.
+// If a following StmtSequence belongs to our CloneGroup, we add it.
 const StmtSequence  = HashGroup[j];
 
 if (!Compare(Prototype, Candidate))


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


[PATCH] D34377: Support MS builtins using 'long' on LP64

2017-06-20 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL305875: Support MS builtins using 'long' on LP64 platforms 
(authored by bruno).

Changed prior to commit:
  https://reviews.llvm.org/D34377?vs=103315=103318#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34377

Files:
  cfe/trunk/include/clang/Basic/Builtins.def
  cfe/trunk/include/clang/Basic/BuiltinsARM.def
  cfe/trunk/include/clang/Basic/BuiltinsX86.def
  cfe/trunk/include/clang/Basic/BuiltinsX86_64.def
  cfe/trunk/lib/AST/ASTContext.cpp
  cfe/trunk/test/CodeGen/ms-intrinsics-other.c
  cfe/trunk/test/CodeGen/ms-intrinsics-rotations.c
  cfe/trunk/test/CodeGen/pr27892.c

Index: cfe/trunk/include/clang/Basic/BuiltinsARM.def
===
--- cfe/trunk/include/clang/Basic/BuiltinsARM.def
+++ cfe/trunk/include/clang/Basic/BuiltinsARM.def
@@ -215,10 +215,10 @@
 LANGBUILTIN(_MoveToCoprocessor, "vUiIUiIUiIUiIUiIUi", "", ALL_MS_LANGUAGES)
 LANGBUILTIN(_MoveToCoprocessor2, "vUiIUiIUiIUiIUiIUi", "", ALL_MS_LANGUAGES)
 
-TARGET_HEADER_BUILTIN(_BitScanForward, "UcULi*ULi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
-TARGET_HEADER_BUILTIN(_BitScanReverse, "UcULi*ULi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
-TARGET_HEADER_BUILTIN(_BitScanForward64, "UcULi*ULLi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
-TARGET_HEADER_BUILTIN(_BitScanReverse64, "UcULi*ULLi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(_BitScanForward, "UcUNi*UNi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(_BitScanReverse, "UcUNi*UNi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(_BitScanForward64, "UcUNi*ULLi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(_BitScanReverse64, "UcUNi*ULLi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
 
 TARGET_HEADER_BUILTIN(_InterlockedAnd64, "LLiLLiD*LLi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
 TARGET_HEADER_BUILTIN(_InterlockedDecrement64,   "LLiLLiD*","nh", "intrin.h", ALL_MS_LANGUAGES, "")
Index: cfe/trunk/include/clang/Basic/BuiltinsX86_64.def
===
--- cfe/trunk/include/clang/Basic/BuiltinsX86_64.def
+++ cfe/trunk/include/clang/Basic/BuiltinsX86_64.def
@@ -22,8 +22,8 @@
 #  define TARGET_HEADER_BUILTIN(ID, TYPE, ATTRS, HEADER, LANG, FEATURE) BUILTIN(ID, TYPE, ATTRS)
 #endif
 
-TARGET_HEADER_BUILTIN(_BitScanForward64, "UcULi*ULLi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
-TARGET_HEADER_BUILTIN(_BitScanReverse64, "UcULi*ULLi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(_BitScanForward64, "UcUNi*ULLi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(_BitScanReverse64, "UcUNi*ULLi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
 
 TARGET_HEADER_BUILTIN(__mulh,  "LLiLLiLLi","nch", "intrin.h", ALL_MS_LANGUAGES, "")
 TARGET_HEADER_BUILTIN(__umulh, "ULLiULLiULLi", "nch", "intrin.h", ALL_MS_LANGUAGES, "")
Index: cfe/trunk/include/clang/Basic/BuiltinsX86.def
===
--- cfe/trunk/include/clang/Basic/BuiltinsX86.def
+++ cfe/trunk/include/clang/Basic/BuiltinsX86.def
@@ -1822,8 +1822,8 @@
 TARGET_BUILTIN(__builtin_ia32_clzero, "vv*", "", "clzero")
 
 // MSVC
-TARGET_HEADER_BUILTIN(_BitScanForward, "UcULi*ULi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
-TARGET_HEADER_BUILTIN(_BitScanReverse, "UcULi*ULi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(_BitScanForward, "UcUNi*UNi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(_BitScanReverse, "UcUNi*UNi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
 
 TARGET_HEADER_BUILTIN(_ReadWriteBarrier, "v", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
 TARGET_HEADER_BUILTIN(_ReadBarrier,  "v", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
@@ -1838,15 +1838,15 @@
 TARGET_HEADER_BUILTIN(__int2c, "v",   "nr", "intrin.h", ALL_MS_LANGUAGES, "")
 TARGET_HEADER_BUILTIN(__ud2,   "v",   "nr", "intrin.h", ALL_MS_LANGUAGES, "")
 
-TARGET_HEADER_BUILTIN(__readfsbyte,  "UcULi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
-TARGET_HEADER_BUILTIN(__readfsword,  "UsULi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
-TARGET_HEADER_BUILTIN(__readfsdword, "ULiULi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
-TARGET_HEADER_BUILTIN(__readfsqword, "ULLiULi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
-
-TARGET_HEADER_BUILTIN(__readgsbyte,  "UcULi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
-TARGET_HEADER_BUILTIN(__readgsword,  "UsULi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
-TARGET_HEADER_BUILTIN(__readgsdword, "ULiULi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
-TARGET_HEADER_BUILTIN(__readgsqword, "ULLiULi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(__readfsbyte,  "UcUNi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(__readfsword,  "UsUNi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(__readfsdword, "UNiUNi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")

r305875 - Support MS builtins using 'long' on LP64 platforms

2017-06-20 Thread Bruno Cardoso Lopes via cfe-commits
Author: bruno
Date: Tue Jun 20 21:20:46 2017
New Revision: 305875

URL: http://llvm.org/viewvc/llvm-project?rev=305875=rev
Log:
Support MS builtins using 'long' on LP64 platforms

This allows for -fms-extensions to work the same on LP64. For example,
_BitScanReverse is expected to be 32-bit, matching Windows/LLP64, even
though long is 64-bit on x86_64 Darwin or Linux (LP64).

Implement this by adding a new character code 'N', which is 'int' if
the target is LP64 and the same 'L' otherwise

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

rdar://problem/32599746

Added:
cfe/trunk/test/CodeGen/ms-intrinsics-other.c
Removed:
cfe/trunk/test/CodeGen/pr27892.c
Modified:
cfe/trunk/include/clang/Basic/Builtins.def
cfe/trunk/include/clang/Basic/BuiltinsARM.def
cfe/trunk/include/clang/Basic/BuiltinsX86.def
cfe/trunk/include/clang/Basic/BuiltinsX86_64.def
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/test/CodeGen/ms-intrinsics-rotations.c

Modified: cfe/trunk/include/clang/Basic/Builtins.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.def?rev=305875=305874=305875=diff
==
--- cfe/trunk/include/clang/Basic/Builtins.def (original)
+++ cfe/trunk/include/clang/Basic/Builtins.def Tue Jun 20 21:20:46 2017
@@ -52,6 +52,7 @@
 //  LL  -> long long
 //  LLL -> __int128_t (e.g. LLLi)
 //  W   -> int64_t
+//  N   -> 'int' size if target is LP64, 'L' otherwise.
 //  S   -> signed
 //  U   -> unsigned
 //  I   -> Required to constant fold to an integer constant expression.
@@ -718,11 +719,11 @@ BUILTIN(__builtin_rindex, "c*cC*i", "Fn"
 LANGBUILTIN(_alloca,  "v*z", "n", ALL_MS_LANGUAGES)
 LANGBUILTIN(__assume, "vb",  "n", ALL_MS_LANGUAGES)
 LIBBUILTIN(_byteswap_ushort, "UsUs", "fnc", "stdlib.h", ALL_MS_LANGUAGES)
-LIBBUILTIN(_byteswap_ulong,  "ULiULi",   "fnc", "stdlib.h", ALL_MS_LANGUAGES)
+LIBBUILTIN(_byteswap_ulong,  "UNiUNi",   "fnc", "stdlib.h", ALL_MS_LANGUAGES)
 LIBBUILTIN(_byteswap_uint64, "ULLiULLi", "fnc", "stdlib.h", ALL_MS_LANGUAGES)
 LANGBUILTIN(__debugbreak, "v",   "n", ALL_MS_LANGUAGES)
-LANGBUILTIN(__exception_code, "ULi", "n", ALL_MS_LANGUAGES)
-LANGBUILTIN(_exception_code,  "ULi", "n", ALL_MS_LANGUAGES)
+LANGBUILTIN(__exception_code, "UNi", "n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_exception_code,  "UNi", "n", ALL_MS_LANGUAGES)
 LANGBUILTIN(__exception_info, "v*",  "n", ALL_MS_LANGUAGES)
 LANGBUILTIN(_exception_info,  "v*",  "n", ALL_MS_LANGUAGES)
 LANGBUILTIN(__abnormal_termination, "i", "n", ALL_MS_LANGUAGES)
@@ -730,33 +731,33 @@ LANGBUILTIN(_abnormal_termination,  "i",
 LANGBUILTIN(__GetExceptionInfo, "v*.", "ntu", ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedAnd8,   "ccD*c","n", ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedAnd16,  "ssD*s","n", ALL_MS_LANGUAGES)
-LANGBUILTIN(_InterlockedAnd,"LiLiD*Li", "n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_InterlockedAnd,"NiNiD*Ni", "n", ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedCompareExchange8,   "ccD*cc", "n", 
ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedCompareExchange16,  "ssD*ss", "n", 
ALL_MS_LANGUAGES)
-LANGBUILTIN(_InterlockedCompareExchange,"LiLiD*LiLi", "n", 
ALL_MS_LANGUAGES)
+LANGBUILTIN(_InterlockedCompareExchange,"NiNiD*NiNi", "n", 
ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedCompareExchange64,  "LLiLLiD*LLiLLi", "n", 
ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedCompareExchangePointer, "v*v*D*v*v*", "n", 
ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedDecrement16,"ssD*", "n", ALL_MS_LANGUAGES)
-LANGBUILTIN(_InterlockedDecrement,  "LiLiD*",   "n", ALL_MS_LANGUAGES)
-LANGBUILTIN(_InterlockedExchange,   "LiLiD*Li", "n", 
ALL_MS_LANGUAGES)
+LANGBUILTIN(_InterlockedDecrement,  "NiNiD*",   "n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_InterlockedExchange,   "NiNiD*Ni", "n", 
ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedExchange8,  "ccD*c","n", 
ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedExchange16, "ssD*s","n", 
ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedExchangeAdd8,   "ccD*c",  "n", 
ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedExchangeAdd16,  "ssD*s",  "n", 
ALL_MS_LANGUAGES)
-LANGBUILTIN(_InterlockedExchangeAdd,"LiLiD*Li",   "n", 
ALL_MS_LANGUAGES)
+LANGBUILTIN(_InterlockedExchangeAdd,"NiNiD*Ni",   "n", 
ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedExchangePointer,"v*v*D*v*",   "n", 
ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedExchangeSub8,   "ccD*c","n", ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedExchangeSub16,  "ssD*s","n", ALL_MS_LANGUAGES)
-LANGBUILTIN(_InterlockedExchangeSub,"LiLiD*Li", "n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_InterlockedExchangeSub,"NiNiD*Ni", "n", ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedIncrement16,"ssD*", "n", ALL_MS_LANGUAGES)
-LANGBUILTIN(_InterlockedIncrement, 

r305874 - Run dos2unix on ms-intrinsics-rotations.c test. NFC

2017-06-20 Thread Bruno Cardoso Lopes via cfe-commits
Author: bruno
Date: Tue Jun 20 21:20:40 2017
New Revision: 305874

URL: http://llvm.org/viewvc/llvm-project?rev=305874=rev
Log:
Run dos2unix on ms-intrinsics-rotations.c test. NFC

Modified:
cfe/trunk/test/CodeGen/ms-intrinsics-rotations.c

Modified: cfe/trunk/test/CodeGen/ms-intrinsics-rotations.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/ms-intrinsics-rotations.c?rev=305874=305873=305874=diff
==
--- cfe/trunk/test/CodeGen/ms-intrinsics-rotations.c (original)
+++ cfe/trunk/test/CodeGen/ms-intrinsics-rotations.c Tue Jun 20 21:20:40 2017
@@ -1,181 +1,181 @@
 // RUN: %clang_cc1 -ffreestanding -fms-extensions -fms-compatibility 
-fms-compatibility-version=17.00 \
 // RUN: -triple i686--windows -emit-llvm %s -o - \
-// RUN: | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG
+// RUN: | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG
 // RUN: %clang_cc1 -ffreestanding -fms-extensions -fms-compatibility 
-fms-compatibility-version=17.00 \
 // RUN: -triple thumbv7--windows -emit-llvm %s -o - \
-// RUN: | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG
+// RUN: | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG
 // RUN: %clang_cc1 -ffreestanding -fms-extensions -fms-compatibility 
-fms-compatibility-version=17.00 \
 // RUN: -triple x86_64--windows -emit-llvm %s -o - \
-// RUN: | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG
+// RUN: | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG
 // RUN: %clang_cc1 -ffreestanding -fms-extensions -fms-compatibility 
-fms-compatibility-version=17.00 \
 // RUN: -triple i686--linux -emit-llvm %s -o - \
-// RUN: | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG
+// RUN: | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG
 // RUN: %clang_cc1 -ffreestanding -fms-extensions -fms-compatibility 
-fms-compatibility-version=17.00 \
 // RUN: -triple x86_64--linux -emit-llvm %s -o - \
-// RUN: | FileCheck %s --check-prefixes CHECK,CHECK-64BIT-LONG
-
-// rotate left
-
-unsigned char test_rotl8(unsigned char value, unsigned char shift) {
-  return _rotl8(value, shift);
-}
-// CHECK: i8 @test_rotl8
-// CHECK:   [[SHIFT:%[0-9]+]] = and i8 %{{[0-9]+}}, 7
-// CHECK:   [[NEGSHIFT:%[0-9]+]] = sub i8 8, [[SHIFT]]
-// CHECK:   [[HIGH:%[0-9]+]] = shl i8 [[VALUE:%[0-9]+]], [[SHIFT]]
-// CHECK:   [[LOW:%[0-9]+]] = lshr i8 [[VALUE]], [[NEGSHIFT]]
-// CHECK:   [[ROTATED:%[0-9]+]] = or i8 [[HIGH]], [[LOW]]
-// CHECK:   [[ISZERO:%[0-9]+]] = icmp eq i8 [[SHIFT]], 0
-// CHECK:   [[RESULT:%[0-9]+]] = select i1 [[ISZERO]], i8 [[VALUE]], i8 
[[ROTATED]]
-// CHECK:   ret i8 [[RESULT]]
-// CHECK  }
-
-unsigned short test_rotl16(unsigned short value, unsigned char shift) {
-  return _rotl16(value, shift);
-}
-// CHECK: i16 @test_rotl16
-// CHECK:   [[SHIFT:%[0-9]+]] = and i16 %{{[0-9]+}}, 15
-// CHECK:   [[NEGSHIFT:%[0-9]+]] = sub i16 16, [[SHIFT]]
-// CHECK:   [[HIGH:%[0-9]+]] = shl i16 [[VALUE:%[0-9]+]], [[SHIFT]]
-// CHECK:   [[LOW:%[0-9]+]] = lshr i16 [[VALUE]], [[NEGSHIFT]]
-// CHECK:   [[ROTATED:%[0-9]+]] = or i16 [[HIGH]], [[LOW]]
-// CHECK:   [[ISZERO:%[0-9]+]] = icmp eq i16 [[SHIFT]], 0
-// CHECK:   [[RESULT:%[0-9]+]] = select i1 [[ISZERO]], i16 [[VALUE]], i16 
[[ROTATED]]
-// CHECK:   ret i16 [[RESULT]]
-// CHECK  }
-
-unsigned int test_rotl(unsigned int value, int shift) {
-  return _rotl(value, shift);
-}
-// CHECK: i32 @test_rotl
-// CHECK:   [[SHIFT:%[0-9]+]] = and i32 %{{[0-9]+}}, 31
-// CHECK:   [[NEGSHIFT:%[0-9]+]] = sub i32 32, [[SHIFT]]
-// CHECK:   [[HIGH:%[0-9]+]] = shl i32 [[VALUE:%[0-9]+]], [[SHIFT]]
-// CHECK:   [[LOW:%[0-9]+]] = lshr i32 [[VALUE]], [[NEGSHIFT]]
-// CHECK:   [[ROTATED:%[0-9]+]] = or i32 [[HIGH]], [[LOW]]
-// CHECK:   [[ISZERO:%[0-9]+]] = icmp eq i32 [[SHIFT]], 0
-// CHECK:   [[RESULT:%[0-9]+]] = select i1 [[ISZERO]], i32 [[VALUE]], i32 
[[ROTATED]]
-// CHECK:   ret i32 [[RESULT]]
-// CHECK  }
-
-unsigned long test_lrotl(unsigned long value, int shift) {
-  return _lrotl(value, shift);
-}
-// CHECK-32BIT-LONG: i32 @test_lrotl
-// CHECK-32BIT-LONG:   [[SHIFT:%[0-9]+]] = and i32 %{{[0-9]+}}, 31
-// CHECK-32BIT-LONG:   [[NEGSHIFT:%[0-9]+]] = sub i32 32, [[SHIFT]]
-// CHECK-32BIT-LONG:   [[HIGH:%[0-9]+]] = shl i32 [[VALUE:%[0-9]+]], [[SHIFT]]
-// CHECK-32BIT-LONG:   [[LOW:%[0-9]+]] = lshr i32 [[VALUE]], [[NEGSHIFT]]
-// CHECK-32BIT-LONG:   [[ROTATED:%[0-9]+]] = or i32 [[HIGH]], [[LOW]]
-// CHECK-32BIT-LONG:   [[ISZERO:%[0-9]+]] = icmp eq i32 [[SHIFT]], 0
-// CHECK-32BIT-LONG:   [[RESULT:%[0-9]+]] = select i1 [[ISZERO]], i32 
[[VALUE]], i32 [[ROTATED]]
-// CHECK-32BIT-LONG:   ret i32 [[RESULT]]
-// CHECK-32BIT-LONG  }
-
-// CHECK-64BIT-LONG: i64 @test_lrotl
-// CHECK-64BIT-LONG:   [[SHIFT:%[0-9]+]] = and i64 %{{[0-9]+}}, 63
-// CHECK-64BIT-LONG:   [[NEGSHIFT:%[0-9]+]] = sub i64 64, [[SHIFT]]
-// CHECK-64BIT-LONG:   [[HIGH:%[0-9]+]] = 

[PATCH] D34426: [Driver] Do not increment ActionCount for precompiled headers.

2017-06-20 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

I am not sure what is the expected behavior. Maybe clang is doing the right 
thing in rejecting. 
But, this creates an issue in ChromeOS land where a package fails to build with 
clang (https://bugs.chromium.org/p/chromium/issues/detail?id=735206).


https://reviews.llvm.org/D34426



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


r305872 - [ODRHash] Supply more information when generic error message is emitted.

2017-06-20 Thread Richard Trieu via cfe-commits
Author: rtrieu
Date: Tue Jun 20 20:43:13 2017
New Revision: 305872

URL: http://llvm.org/viewvc/llvm-project?rev=305872=rev
Log:
[ODRHash] Supply more information when generic error message is emitted.

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
cfe/trunk/lib/Serialization/ASTReader.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td?rev=305872=305871=305872=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td Tue Jun 20 
20:43:13 2017
@@ -112,8 +112,13 @@ def note_module_odr_violation_possible_d
 def err_module_odr_violation_different_definitions : Error<
   "%q0 has different definitions in different modules; "
   "%select{definition in module '%2' is here|defined here}1">;
+def note_first_module_difference : Note<
+  "in first definition, possible difference is here">;
 def note_module_odr_violation_different_definitions : Note<
   "definition in module '%0' is here">;
+def note_second_module_difference : Note<
+  "in second definition, possible difference is here">;
+
 def err_module_odr_violation_different_instantiations : Error<
   "instantiation of %q0 is different in different modules">;
 

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=305872=305871=305872=diff
==
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Tue Jun 20 20:43:13 2017
@@ -9324,9 +9324,20 @@ void ASTReader::diagnoseOdrViolations()
  diag::err_module_odr_violation_different_definitions)
 << FirstRecord << FirstModule.empty() << FirstModule;
 
+if (FirstDecl) {
+  Diag(FirstDecl->getLocation(), diag::note_first_module_difference)
+  << FirstRecord << FirstDecl->getSourceRange();
+}
+
 Diag(SecondRecord->getLocation(),
  diag::note_module_odr_violation_different_definitions)
 << SecondModule;
+
+if (SecondDecl) {
+  Diag(SecondDecl->getLocation(), diag::note_second_module_difference)
+  << SecondDecl->getSourceRange();
+}
+
 Diagnosed = true;
 break;
   }


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


[PATCH] D34377: Support MS builtins using 'long' on LP64

2017-06-20 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.

lgtm, thanks for shuffling all the tests around!


https://reviews.llvm.org/D34377



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


[PATCH] D34377: Support MS builtins using 'long' on LP64

2017-06-20 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno updated this revision to Diff 103315.
bruno marked an inline comment as done.
bruno added a comment.

Addressing comments!


https://reviews.llvm.org/D34377

Files:
  include/clang/Basic/Builtins.def
  include/clang/Basic/BuiltinsARM.def
  include/clang/Basic/BuiltinsX86.def
  include/clang/Basic/BuiltinsX86_64.def
  lib/AST/ASTContext.cpp
  test/CodeGen/ms-intrinsics-other.c
  test/CodeGen/ms-intrinsics-rotations.c
  test/CodeGen/pr27892.c

Index: test/CodeGen/pr27892.c
===
--- test/CodeGen/pr27892.c
+++ /dev/null
@@ -1,23 +0,0 @@
-// RUN: %clang_cc1 -triple x86_64-linux-gnu -fms-extensions %s -emit-llvm -o - | FileCheck %s
-
-long test1(long *p) {
-  return _InterlockedIncrement(p);
-}
-// CHECK-DAG: define i64 @test1(
-// CHECK:   %[[p_addr:.*]] = alloca i64*, align 8
-// CHECK:   store i64* %p, i64** %[[p_addr]], align 8
-// CHECK:   %[[p_load:.*]] = load i64*, i64** %[[p_addr]], align 8
-// CHECK:   %[[atomic_add:.*]] = atomicrmw add i64* %[[p_load]], i64 1 seq_cst
-// CHECK:   %[[res:.*]] = add i64 %[[atomic_add]], 1
-// CHECK:   ret i64 %[[res]]
-
-long test2(long *p) {
-  return _InterlockedDecrement(p);
-}
-// CHECK-DAG: define i64 @test2(
-// CHECK:   %[[p_addr:.*]] = alloca i64*, align 8
-// CHECK:   store i64* %p, i64** %[[p_addr]], align 8
-// CHECK:   %[[p_load:.*]] = load i64*, i64** %[[p_addr]], align 8
-// CHECK:   %[[atomic_sub:.*]] = atomicrmw sub i64* %[[p_load]], i64 1 seq_cst
-// CHECK:   %[[res:.*]] = sub i64 %[[atomic_sub]], 1
-// CHECK:   ret i64 %[[res]]
Index: test/CodeGen/ms-intrinsics-rotations.c
===
--- test/CodeGen/ms-intrinsics-rotations.c
+++ test/CodeGen/ms-intrinsics-rotations.c
@@ -12,7 +12,17 @@
 // RUN: | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG
 // RUN: %clang_cc1 -ffreestanding -fms-extensions -fms-compatibility -fms-compatibility-version=17.00 \
 // RUN: -triple x86_64--linux -emit-llvm %s -o - \
-// RUN: | FileCheck %s --check-prefixes CHECK,CHECK-64BIT-LONG
+// RUN: | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG
+// RUN: %clang_cc1 -ffreestanding -fms-extensions \
+// RUN: -triple x86_64--darwin -emit-llvm %s -o - \
+// RUN: | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG
+
+// LP64 targets use 'long' as 'int' for MS intrinsics (-fms-extensions)
+#ifdef __LP64__
+#define LONG int
+#else
+#define LONG long
+#endif
 
 // rotate left
 
@@ -58,7 +68,7 @@
 // CHECK:   ret i32 [[RESULT]]
 // CHECK  }
 
-unsigned long test_lrotl(unsigned long value, int shift) {
+unsigned LONG test_lrotl(unsigned LONG value, int shift) {
   return _lrotl(value, shift);
 }
 // CHECK-32BIT-LONG: i32 @test_lrotl
@@ -72,17 +82,6 @@
 // CHECK-32BIT-LONG:   ret i32 [[RESULT]]
 // CHECK-32BIT-LONG  }
 
-// CHECK-64BIT-LONG: i64 @test_lrotl
-// CHECK-64BIT-LONG:   [[SHIFT:%[0-9]+]] = and i64 %{{[0-9]+}}, 63
-// CHECK-64BIT-LONG:   [[NEGSHIFT:%[0-9]+]] = sub i64 64, [[SHIFT]]
-// CHECK-64BIT-LONG:   [[HIGH:%[0-9]+]] = shl i64 [[VALUE:%[0-9]+]], [[SHIFT]]
-// CHECK-64BIT-LONG:   [[LOW:%[0-9]+]] = lshr i64 [[VALUE]], [[NEGSHIFT]]
-// CHECK-64BIT-LONG:   [[ROTATED:%[0-9]+]] = or i64 [[HIGH]], [[LOW]]
-// CHECK-64BIT-LONG:   [[ISZERO:%[0-9]+]] = icmp eq i64 [[SHIFT]], 0
-// CHECK-64BIT-LONG:   [[RESULT:%[0-9]+]] = select i1 [[ISZERO]], i64 [[VALUE]], i64 [[ROTATED]]
-// CHECK-64BIT-LONG:   ret i64 [[RESULT]]
-// CHECK-64BIT-LONG  }
-
 unsigned __int64 test_rotl64(unsigned __int64 value, int shift) {
   return _rotl64(value, shift);
 }
@@ -141,7 +140,7 @@
 // CHECK:   ret i32 [[RESULT]]
 // CHECK  }
 
-unsigned long test_lrotr(unsigned long value, int shift) {
+unsigned LONG test_lrotr(unsigned LONG value, int shift) {
   return _lrotr(value, shift);
 }
 // CHECK-32BIT-LONG: i32 @test_lrotr
@@ -155,17 +154,6 @@
 // CHECK-32BIT-LONG:   ret i32 [[RESULT]]
 // CHECK-32BIT-LONG  }
 
-// CHECK-64BIT-LONG: i64 @test_lrotr
-// CHECK-64BIT-LONG:   [[SHIFT:%[0-9]+]] = and i64 %{{[0-9]+}}, 63
-// CHECK-64BIT-LONG:   [[NEGSHIFT:%[0-9]+]] = sub i64 64, [[SHIFT]]
-// CHECK-64BIT-LONG:   [[LOW:%[0-9]+]] = lshr i64 [[VALUE:%[0-9]+]], [[SHIFT]]
-// CHECK-64BIT-LONG:   [[HIGH:%[0-9]+]] = shl i64 [[VALUE]], [[NEGSHIFT]]
-// CHECK-64BIT-LONG:   [[ROTATED:%[0-9]+]] = or i64 [[HIGH]], [[LOW]]
-// CHECK-64BIT-LONG:   [[ISZERO:%[0-9]+]] = icmp eq i64 [[SHIFT]], 0
-// CHECK-64BIT-LONG:   [[RESULT:%[0-9]+]] = select i1 [[ISZERO]], i64 [[VALUE]], i64 [[ROTATED]]
-// CHECK-64BIT-LONG:   ret i64 [[RESULT]]
-// CHECK-64BIT-LONG  }
-
 unsigned __int64 test_rotr64(unsigned __int64 value, int shift) {
   return _rotr64(value, shift);
 }
Index: test/CodeGen/ms-intrinsics-other.c
===
--- /dev/null
+++ test/CodeGen/ms-intrinsics-other.c
@@ -0,0 +1,161 @@
+// RUN: %clang_cc1 -ffreestanding -fms-extensions \
+// RUN: -triple x86_64--darwin -Oz -emit-llvm %s -o 

[PATCH] D34377: Support MS builtins using 'long' on LP64

2017-06-20 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno marked 3 inline comments as done.
bruno added inline comments.



Comment at: test/CodeGen/ms-intrinsics-darwin.c:1
+// RUN: %clang_cc1 -ffreestanding -fms-extensions \
+// RUN: -triple x86_64--darwin -Oz -emit-llvm %s -o - \

rnk wrote:
> I'd rather generalize `test/CodeGen/ms-intrinsics.c` to cover Darwin as well 
> as Windows & Linux.
ms-intrinsics.c currently includes intrin.h and does not cover linux. Instead 
I'm going to rename this ms-intrinsics-other.c, test for linux as well and 
cover the content from pr27892.c.


https://reviews.llvm.org/D34377



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


[PATCH] D32332: Add support for transparent overloadable functions in clang

2017-06-20 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: include/clang/Basic/AttrDocs.td:608-611
 declarations and definitions.  Most importantly, if any function with a given
 name is given the ``overloadable`` attribute, then all function declarations
 and definitions with that name (and in that scope) must have the
 ``overloadable`` attribute.  This rule even applies to redeclarations of

Can you update this to point out the exception below?



Comment at: include/clang/Basic/DiagnosticSemaKinds.td:3294-3295
+def err_attribute_overloadable_multiple_unmarked_overloads : Error<
+  "at most one 'overloadable' function for a given name may lack the "
+  "'overloadable' attribute">;
 def warn_ns_attribute_wrong_return_type : Warning<

I think calling the functions 'overloadable' in this case is confusing.



Comment at: lib/Lex/PPMacroExpansion.cpp:1136
   .Case("nullability_on_arrays", true)
+  .Case("overloadable_unmarked", true)
   .Case("memory_sanitizer", LangOpts.Sanitize.has(SanitizerKind::Memory))

Should this be `__has_extension` rather than `__has_feature`, since it's not a 
standard feature? (Per 
http://clang.llvm.org/docs/LanguageExtensions.html#has-feature-and-has-extension
 `__has_feature` is only for detecting standard features, despite us using it 
for other things.)



Comment at: lib/Sema/SemaDecl.cpp:9249-9252
+case Ovl_Match:
+  // We're not guaranteed to be handed the most recent decl, and
+  // __attribute__((overloadable)) depends somewhat on source order.
+  OldDecl = OldDecl->getMostRecentDecl();

`checkForConflictWithnonVisibleExternC` should probably be responsible for 
finding the most recent declaration of the entity that is actually visible (and 
not, say, a block-scope declaration in some unrelated function, or a 
declaration in an unimported module).



Comment at: lib/Sema/SemaDecl.cpp:9375-9381
+assert((Previous.empty() ||
+llvm::any_of(
+Previous,
+[](const NamedDecl *ND) {
+  return ND->getMostRecentDecl()->hasAttr();
+})) &&
+   "Non-redecls shouldn't happen without overloadable present");

Seems worth factoring out this "contains any overloadable functions" check, 
since it's quite a few lines and you're doing it in two different places.



Comment at: test/Sema/overloadable.c:112
   void (*ptr2)(char *) = 
-  void (*ambiguous)(int *) =  // expected-error{{initializing 'void 
(*)(int *)' with an expression of incompatible type ''}} expected-note@105{{candidate function}} expected-note@106{{candidate 
function}}
-  void *vp_ambiguous =  // expected-error{{initializing 'void *' with an 
expression of incompatible type ''}} 
expected-note@105{{candidate function}} expected-note@106{{candidate function}}
+  void (*ambiguous)(int *) =  // expected-error{{initializing 'void 
(*)(int *)' with an expression of incompatible type ''}} expected-note@-4{{candidate function}} expected-note@-3{{candidate 
function}}
+  void *vp_ambiguous =  // expected-error{{initializing 'void *' with an 
expression of incompatible type ''}} 
expected-note@-5{{candidate function}} expected-note@-4{{candidate function}}

It'd be nice to check in these changes from @NNN -> @-M separately.


https://reviews.llvm.org/D32332



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


[PATCH] D34377: Support MS builtins using 'long' on LP64

2017-06-20 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added inline comments.



Comment at: include/clang/Basic/Builtins.def:55
 //  W   -> int64_t
+//  N   -> 'L' if target is LP64, 'int' size otherwise.
 //  S   -> signed

Fix the comment? "long" if target is LLP64, "int" otherwise?



Comment at: test/CodeGen/ms-intrinsics-darwin.c:1
+// RUN: %clang_cc1 -ffreestanding -fms-extensions \
+// RUN: -triple x86_64--darwin -Oz -emit-llvm %s -o - \

I'd rather generalize `test/CodeGen/ms-intrinsics.c` to cover Darwin as well as 
Windows & Linux.



Comment at: test/CodeGen/ms-intrinsics-darwin.c:45
+}
+// CHECK-ARM-X64: define{{.*}}i8 @test_BitScanForward64(i32* {{[a-z_ 
]*}}%Index, i64 {{[a-z_ ]*}}%Mask){{.*}}{
+// CHECK-ARM-X64:   [[ISNOTZERO:%[a-z0-9._]+]] = icmp eq i64 %Mask, 0

You don't have a RUN: line for this.


https://reviews.llvm.org/D34377



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


[PATCH] D34430: [Clang][TypoCorrection] Clang hangs in typo correction

2017-06-20 Thread Oleg Ranevskyy via Phabricator via cfe-commits
iid_iunknown updated this revision to Diff 103297.
iid_iunknown added a comment.

Fixed white spaces.


Repository:
  rL LLVM

https://reviews.llvm.org/D34430

Files:
  lib/Sema/SemaExprCXX.cpp


Index: lib/Sema/SemaExprCXX.cpp
===
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -7246,10 +7246,13 @@
   /// TransformCache). Returns true if there is still any untried combinations
   /// of corrections.
   bool CheckAndAdvanceTypoExprCorrectionStreams() {
+bool CheckLimitExceeded =
+SemaRef.TyposCorrected >=
+SemaRef.getDiagnostics().getDiagnosticOptions().SpellCheckingLimit;
 for (auto TE : TypoExprs) {
   auto  = SemaRef.getTypoExprState(TE);
   TransformCache.erase(TE);
-  if (!State.Consumer->finished())
+  if (!CheckLimitExceeded && !State.Consumer->finished())
 return true;
   State.Consumer->resetCorrectionStream();
 }


Index: lib/Sema/SemaExprCXX.cpp
===
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -7246,10 +7246,13 @@
   /// TransformCache). Returns true if there is still any untried combinations
   /// of corrections.
   bool CheckAndAdvanceTypoExprCorrectionStreams() {
+bool CheckLimitExceeded =
+SemaRef.TyposCorrected >=
+SemaRef.getDiagnostics().getDiagnosticOptions().SpellCheckingLimit;
 for (auto TE : TypoExprs) {
   auto  = SemaRef.getTypoExprState(TE);
   TransformCache.erase(TE);
-  if (!State.Consumer->finished())
+  if (!CheckLimitExceeded && !State.Consumer->finished())
 return true;
   State.Consumer->resetCorrectionStream();
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34430: [Clang][TypoCorrection] Clang hangs in typo correction

2017-06-20 Thread Oleg Ranevskyy via Phabricator via cfe-commits
iid_iunknown created this revision.
iid_iunknown added a project: clang.

This is a patch for PR33484.
The clang's typo correction logic may fall into an infinite loop when reaching 
the typo correction limit.

When some complex expression has multiple typos in it, clang finds possible 
corrections for each typo and processes various permutations of these 
corrections. The typo corrections counter is incremented during the process and 
compared to the max allowed limit (50 by default). Hang may happen if the limit 
is reached in the middle of complex expression processing. In this case 
transform of the current part of the expression fails, making clang ignore its 
subsequent parts and bail out to the main transform loop in 
`TransformTypos::Transform(Expr *E)`. On the next iteration, clang fails at the 
very beginning of transform and no longer reaches the rest of the expression 
immediately bailing out to the main loop. The transform cannot advance since 
this moment. As the loop exit condition requires either a fully successful 
transform or having all the permutations processed, it can never become true.

Yet another reproducer with a readable C++ code:

  namespace
  {
struct V
{
  float x;
};
  
class H
{
public:
  const V& getV() const { return mV; }
  int getN() const { return mN; }
private:
  V mV;
  int mN;
};
  
class T
{
public:
  const H& getH0() const { return mH0; }
  const H& getH1() const { return mH1; }
  
  const V& getV0() const { return mH0.getV(); }
  const V& getV1() const { return mH1.getV(); }
  
private:
  H mH0;
  H mH1;
};

T sT;
H sH;
  }
  
  void func()
  {
( sT.getH2().getM() > sH.getM() ?
  sT.getH3() :
  0 );
  }

Here, both the condition and LHS of `?:` have typos. If the limit is exceeded, 
the transform will fail on the condition and will no longer proceed to LHS and 
process its substitutions.

The patch adds a limit check into the main loop exit condition.


Repository:
  rL LLVM

https://reviews.llvm.org/D34430

Files:
  lib/Sema/SemaExprCXX.cpp


Index: lib/Sema/SemaExprCXX.cpp
===
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -7246,10 +7246,13 @@
   /// TransformCache). Returns true if there is still any untried combinations
   /// of corrections.
   bool CheckAndAdvanceTypoExprCorrectionStreams() {
+   bool CheckLimitExceeded =
+SemaRef.TyposCorrected >=
+SemaRef.getDiagnostics().getDiagnosticOptions().SpellCheckingLimit;
 for (auto TE : TypoExprs) {
   auto  = SemaRef.getTypoExprState(TE);
   TransformCache.erase(TE);
-  if (!State.Consumer->finished())
+ if (!CheckLimitExceeded && !State.Consumer->finished())
 return true;
   State.Consumer->resetCorrectionStream();
 }


Index: lib/Sema/SemaExprCXX.cpp
===
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -7246,10 +7246,13 @@
   /// TransformCache). Returns true if there is still any untried combinations
   /// of corrections.
   bool CheckAndAdvanceTypoExprCorrectionStreams() {
+	bool CheckLimitExceeded =
+SemaRef.TyposCorrected >=
+SemaRef.getDiagnostics().getDiagnosticOptions().SpellCheckingLimit;
 for (auto TE : TypoExprs) {
   auto  = SemaRef.getTypoExprState(TE);
   TransformCache.erase(TE);
-  if (!State.Consumer->finished())
+	  if (!CheckLimitExceeded && !State.Consumer->finished())
 return true;
   State.Consumer->resetCorrectionStream();
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34304: Allow CompilerInvocations to generate .d files.

2017-06-20 Thread Sterling Augustine via Phabricator via cfe-commits
saugustine added a comment.

In https://reviews.llvm.org/D34304#785984, @saugustine wrote:

> In https://reviews.llvm.org/D34304#785083, @klimek wrote:
>
> > I think it's cleaner, because it uses a concept we already have (argument 
> > adapters).
>
>
> Will you point me to an example of these. Google is coming up empty.


Actually, now that I figured out you mean ArgumentAdjusters, I am making 
progress.


https://reviews.llvm.org/D34304



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


[PATCH] D34377: Support MS builtins using 'long' on LP64

2017-06-20 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno updated this revision to Diff 103287.
bruno retitled this revision from "Support MS builtins using 'long' on 
Darwin/LP64" to "Support MS builtins using 'long' on LP64".
bruno edited the summary of this revision.
bruno added a comment.

New patch addressing comments from reviewers.


https://reviews.llvm.org/D34377

Files:
  include/clang/Basic/Builtins.def
  include/clang/Basic/BuiltinsARM.def
  include/clang/Basic/BuiltinsX86.def
  include/clang/Basic/BuiltinsX86_64.def
  lib/AST/ASTContext.cpp
  test/CodeGen/ms-intrinsics-darwin.c
  test/CodeGen/ms-intrinsics-rotations.c
  test/CodeGen/pr27892.c

Index: test/CodeGen/pr27892.c
===
--- test/CodeGen/pr27892.c
+++ test/CodeGen/pr27892.c
@@ -1,23 +1,30 @@
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -fms-extensions %s -emit-llvm -o - | FileCheck %s
 
-long test1(long *p) {
+// LP64 targets use 'long' as 'int' for MS intrinsics (-fms-extensions)
+#ifdef __LP64__
+#define LONG int
+#else
+#define LONG long
+#endif
+
+LONG test1(LONG *p) {
   return _InterlockedIncrement(p);
 }
-// CHECK-DAG: define i64 @test1(
-// CHECK:   %[[p_addr:.*]] = alloca i64*, align 8
-// CHECK:   store i64* %p, i64** %[[p_addr]], align 8
-// CHECK:   %[[p_load:.*]] = load i64*, i64** %[[p_addr]], align 8
-// CHECK:   %[[atomic_add:.*]] = atomicrmw add i64* %[[p_load]], i64 1 seq_cst
-// CHECK:   %[[res:.*]] = add i64 %[[atomic_add]], 1
-// CHECK:   ret i64 %[[res]]
+// CHECK-DAG: define i32 @test1(
+// CHECK:   %[[p_addr:.*]] = alloca i32*, align 8
+// CHECK:   store i32* %p, i32** %[[p_addr]], align 8
+// CHECK:   %[[p_load:.*]] = load i32*, i32** %[[p_addr]], align 8
+// CHECK:   %[[atomic_add:.*]] = atomicrmw add i32* %[[p_load]], i32 1 seq_cst
+// CHECK:   %[[res:.*]] = add i32 %[[atomic_add]], 1
+// CHECK:   ret i32 %[[res]]
 
-long test2(long *p) {
+LONG test2(LONG *p) {
   return _InterlockedDecrement(p);
 }
-// CHECK-DAG: define i64 @test2(
-// CHECK:   %[[p_addr:.*]] = alloca i64*, align 8
-// CHECK:   store i64* %p, i64** %[[p_addr]], align 8
-// CHECK:   %[[p_load:.*]] = load i64*, i64** %[[p_addr]], align 8
-// CHECK:   %[[atomic_sub:.*]] = atomicrmw sub i64* %[[p_load]], i64 1 seq_cst
-// CHECK:   %[[res:.*]] = sub i64 %[[atomic_sub]], 1
-// CHECK:   ret i64 %[[res]]
+// CHECK-DAG: define i32 @test2(
+// CHECK:   %[[p_addr:.*]] = alloca i32*, align 8
+// CHECK:   store i32* %p, i32** %[[p_addr]], align 8
+// CHECK:   %[[p_load:.*]] = load i32*, i32** %[[p_addr]], align 8
+// CHECK:   %[[atomic_sub:.*]] = atomicrmw sub i32* %[[p_load]], i32 1 seq_cst
+// CHECK:   %[[res:.*]] = sub i32 %[[atomic_sub]], 1
+// CHECK:   ret i32 %[[res]]
Index: test/CodeGen/ms-intrinsics-rotations.c
===
--- test/CodeGen/ms-intrinsics-rotations.c
+++ test/CodeGen/ms-intrinsics-rotations.c
@@ -12,7 +12,17 @@
 // RUN: | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG
 // RUN: %clang_cc1 -ffreestanding -fms-extensions -fms-compatibility -fms-compatibility-version=17.00 \
 // RUN: -triple x86_64--linux -emit-llvm %s -o - \
-// RUN: | FileCheck %s --check-prefixes CHECK,CHECK-64BIT-LONG
+// RUN: | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG
+// RUN: %clang_cc1 -ffreestanding -fms-extensions \
+// RUN: -triple x86_64--darwin -emit-llvm %s -o - \
+// RUN: | FileCheck %s --check-prefixes CHECK,CHECK-32BIT-LONG
+
+// LP64 targets use 'long' as 'int' for MS intrinsics (-fms-extensions)
+#ifdef __LP64__
+#define LONG int
+#else
+#define LONG long
+#endif
 
 // rotate left
 
@@ -58,7 +68,7 @@
 // CHECK:   ret i32 [[RESULT]]
 // CHECK  }
 
-unsigned long test_lrotl(unsigned long value, int shift) {
+unsigned LONG test_lrotl(unsigned LONG value, int shift) {
   return _lrotl(value, shift);
 }
 // CHECK-32BIT-LONG: i32 @test_lrotl
@@ -72,17 +82,6 @@
 // CHECK-32BIT-LONG:   ret i32 [[RESULT]]
 // CHECK-32BIT-LONG  }
 
-// CHECK-64BIT-LONG: i64 @test_lrotl
-// CHECK-64BIT-LONG:   [[SHIFT:%[0-9]+]] = and i64 %{{[0-9]+}}, 63
-// CHECK-64BIT-LONG:   [[NEGSHIFT:%[0-9]+]] = sub i64 64, [[SHIFT]]
-// CHECK-64BIT-LONG:   [[HIGH:%[0-9]+]] = shl i64 [[VALUE:%[0-9]+]], [[SHIFT]]
-// CHECK-64BIT-LONG:   [[LOW:%[0-9]+]] = lshr i64 [[VALUE]], [[NEGSHIFT]]
-// CHECK-64BIT-LONG:   [[ROTATED:%[0-9]+]] = or i64 [[HIGH]], [[LOW]]
-// CHECK-64BIT-LONG:   [[ISZERO:%[0-9]+]] = icmp eq i64 [[SHIFT]], 0
-// CHECK-64BIT-LONG:   [[RESULT:%[0-9]+]] = select i1 [[ISZERO]], i64 [[VALUE]], i64 [[ROTATED]]
-// CHECK-64BIT-LONG:   ret i64 [[RESULT]]
-// CHECK-64BIT-LONG  }
-
 unsigned __int64 test_rotl64(unsigned __int64 value, int shift) {
   return _rotl64(value, shift);
 }
@@ -141,7 +140,7 @@
 // CHECK:   ret i32 [[RESULT]]
 // CHECK  }
 
-unsigned long test_lrotr(unsigned long value, int shift) {
+unsigned LONG test_lrotr(unsigned LONG value, int shift) {
   return _lrotr(value, shift);
 }
 // CHECK-32BIT-LONG: i32 @test_lrotr
@@ -155,17 +154,6 

[PATCH] D34198: Fix __has_trivial_destructor crash when the type is incomplete with unknown array bounds.

2017-06-20 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: lib/Sema/SemaExprCXX.cpp:4088-4089
 
   // C++1z [meta.unary.prop]:
   //   remove_all_extents_t shall be a complete type or cv void.
   case UTT_IsAggregate:

Please move the UTT_Has* cases up here, since this is the rule that actually 
applies to them.



Comment at: lib/Sema/SemaExprCXX.cpp:4109
+Loc, ArgTy, diag::err_incomplete_type_used_in_type_trait_expr);
   // Per the GCC type traits documentation, the same constraints apply to 
these.
   case UTT_HasNothrowAssign:

Please update this comment to indicate that the GCC documentation is wrong 
about the constraints that GCC actually imposes on these traits.


https://reviews.llvm.org/D34198



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


Re: r305850 - Preserve CXX method overrides in ASTImporter

2017-06-20 Thread Lang Hames via cfe-commits
Should be fixed in r305860.

- Lang.

On Tue, Jun 20, 2017 at 2:19 PM, Lang Hames  wrote:

> Oops - this broke Sema/ms_class_layout.cpp. Looking in to it now...
>
> - Lang.
>
> On Tue, Jun 20, 2017 at 2:06 PM, Lang Hames via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: lhames
>> Date: Tue Jun 20 16:06:00 2017
>> New Revision: 305850
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=305850=rev
>> Log:
>> Preserve CXX method overrides in ASTImporter
>>
>> Summary:
>> The ASTImporter should import CXX method overrides from the source context
>> when it imports a method decl.
>>
>> Reviewers: spyffe, rsmith, doug.gregor
>>
>> Reviewed By: spyffe
>>
>> Differential Revision: https://reviews.llvm.org/D34371
>>
>> Modified:
>> cfe/trunk/lib/AST/ASTDumper.cpp
>> cfe/trunk/lib/AST/ASTImporter.cpp
>> cfe/trunk/tools/clang-import-test/clang-import-test.cpp
>>
>> Modified: cfe/trunk/lib/AST/ASTDumper.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTDum
>> per.cpp?rev=305850=305849=305850=diff
>> 
>> ==
>> --- cfe/trunk/lib/AST/ASTDumper.cpp (original)
>> +++ cfe/trunk/lib/AST/ASTDumper.cpp Tue Jun 20 16:06:00 2017
>> @@ -1184,6 +1184,28 @@ void ASTDumper::VisitFunctionDecl(const
>>   I != E; ++I)
>>dumpCXXCtorInitializer(*I);
>>
>> +  if (const CXXMethodDecl *MD = dyn_cast(D))
>> +if (MD->size_overridden_methods() != 0) {
>> +  auto dumpOverride =
>> +[=](const CXXMethodDecl *D) {
>> +  SplitQualType T_split = D->getType().split();
>> +  OS << D << " " << D->getParent()->getName() << "::"
>> + << D->getName() << " '"
>> + << QualType::getAsString(T_split) << "'";
>> +};
>> +
>> +  dumpChild([=] {
>> +auto FirstOverrideItr = MD->begin_overridden_methods();
>> +OS << "Overrides: [ ";
>> +dumpOverride(*FirstOverrideItr);
>> +for (const auto *Override :
>> +   llvm::make_range(FirstOverrideItr + 1,
>> +MD->end_overridden_methods()))
>> +  dumpOverride(Override);
>> +OS << " ]";
>> +  });
>> +}
>> +
>>if (D->doesThisDeclarationHaveABody())
>>  dumpStmt(D->getBody());
>>  }
>>
>> Modified: cfe/trunk/lib/AST/ASTImporter.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImp
>> orter.cpp?rev=305850=305849=305850=diff
>> 
>> ==
>> --- cfe/trunk/lib/AST/ASTImporter.cpp (original)
>> +++ cfe/trunk/lib/AST/ASTImporter.cpp Tue Jun 20 16:06:00 2017
>> @@ -319,6 +319,9 @@ namespace clang {
>>  bool ImportArrayChecked(const InContainerTy , OIter
>> Obegin) {
>>return ImportArrayChecked(InContainer.begin(), InContainer.end(),
>> Obegin);
>>  }
>> +
>> +// Importing overrides.
>> +void ImportOverrides(CXXMethodDecl *ToMethod, CXXMethodDecl
>> *FromMethod);
>>};
>>  }
>>
>> @@ -2025,6 +2028,9 @@ Decl *ASTNodeImporter::VisitFunctionDecl
>>// Add this function to the lexical context.
>>LexicalDC->addDeclInternal(ToFunction);
>>
>> +  if (auto *FromCXXMethod = dyn_cast(D))
>> +ImportOverrides(cast(ToFunction), FromCXXMethod);
>> +
>>return ToFunction;
>>  }
>>
>> @@ -5499,6 +5505,14 @@ Expr *ASTNodeImporter::VisitSubstNonType
>>  Replacement);
>>  }
>>
>> +void ASTNodeImporter::ImportOverrides(CXXMethodDecl *ToMethod,
>> +  CXXMethodDecl *FromMethod) {
>> +  for (auto *FromOverriddenMethod : FromMethod->overridden_methods())
>> +ToMethod->addOverriddenMethod(
>> +  cast(Importer.Import(const_cast(
>> +FromOverriddenMethod;
>> +}
>> +
>>  ASTImporter::ASTImporter(ASTContext , FileManager
>> ,
>>   ASTContext , FileManager
>> ,
>>   bool MinimalImport)
>>
>> Modified: cfe/trunk/tools/clang-import-test/clang-import-test.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-im
>> port-test/clang-import-test.cpp?rev=305850=305849=305850=diff
>> 
>> ==
>> --- cfe/trunk/tools/clang-import-test/clang-import-test.cpp (original)
>> +++ cfe/trunk/tools/clang-import-test/clang-import-test.cpp Tue Jun 20
>> 16:06:00 2017
>> @@ -17,7 +17,9 @@
>>  #include "clang/Basic/TargetInfo.h"
>>  #include "clang/Basic/TargetOptions.h"
>>  #include "clang/CodeGen/ModuleBuilder.h"
>> +#include "clang/Frontend/ASTConsumers.h"
>>  #include "clang/Frontend/CompilerInstance.h"
>> +#include "clang/Frontend/MultiplexConsumer.h"
>>  #include "clang/Frontend/TextDiagnosticBuffer.h"
>>  #include "clang/Lex/Lexer.h"
>>  #include "clang/Lex/Preprocessor.h"
>> @@ -51,6 +53,10 @@ static llvm::cl::list
>>llvm::cl::desc("Argument to pass to the

[PATCH] D34426: [Driver] Do not increment ActionCount for precompiled headers.

2017-06-20 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta updated this revision to Diff 103280.

https://reviews.llvm.org/D34426

Files:
  lib/Driver/Driver.cpp


Index: lib/Driver/Driver.cpp
===
--- lib/Driver/Driver.cpp
+++ lib/Driver/Driver.cpp
@@ -2759,7 +2759,7 @@
   if (FinalOutput) {
 unsigned NumOutputs = 0;
 for (const Action *A : C.getActions())
-  if (A->getType() != types::TY_Nothing)
+  if (A->getType() != types::TY_Nothing && A->getType() != types::TY_PCH)
 ++NumOutputs;
 
 if (NumOutputs > 1) {


Index: lib/Driver/Driver.cpp
===
--- lib/Driver/Driver.cpp
+++ lib/Driver/Driver.cpp
@@ -2759,7 +2759,7 @@
   if (FinalOutput) {
 unsigned NumOutputs = 0;
 for (const Action *A : C.getActions())
-  if (A->getType() != types::TY_Nothing)
+  if (A->getType() != types::TY_Nothing && A->getType() != types::TY_PCH)
 ++NumOutputs;
 
 if (NumOutputs > 1) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34426: [Driver] Do not increment ActionCount for precompiled headers.

2017-06-20 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta created this revision.

If a .h file is specifed as input, it gets compiled to a PCH file.
Handle the PCH Action and do not throw the error:
"cannot specify -o when generating multiple output files"

This fixes PR33533.


https://reviews.llvm.org/D34426

Files:
  lib/Driver/Driver.cpp


Index: lib/Driver/Driver.cpp
===
--- lib/Driver/Driver.cpp
+++ lib/Driver/Driver.cpp
@@ -76,6 +76,7 @@
 #if LLVM_ON_UNIX
 #include  // getpid
 #endif
+#include 
 
 using namespace clang::driver;
 using namespace clang;
@@ -2759,7 +2760,7 @@
   if (FinalOutput) {
 unsigned NumOutputs = 0;
 for (const Action *A : C.getActions())
-  if (A->getType() != types::TY_Nothing)
+  if (A->getType() != types::TY_Nothing && A->getType() != types::TY_PCH)
 ++NumOutputs;
 
 if (NumOutputs > 1) {


Index: lib/Driver/Driver.cpp
===
--- lib/Driver/Driver.cpp
+++ lib/Driver/Driver.cpp
@@ -76,6 +76,7 @@
 #if LLVM_ON_UNIX
 #include  // getpid
 #endif
+#include 
 
 using namespace clang::driver;
 using namespace clang;
@@ -2759,7 +2760,7 @@
   if (FinalOutput) {
 unsigned NumOutputs = 0;
 for (const Action *A : C.getActions())
-  if (A->getType() != types::TY_Nothing)
+  if (A->getType() != types::TY_Nothing && A->getType() != types::TY_PCH)
 ++NumOutputs;
 
 if (NumOutputs > 1) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r305860 - Special-case handling of destructors in override lists when dumping ASTs.

2017-06-20 Thread Richard Smith via cfe-commits
On 20 June 2017 at 14:30, Lang Hames via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: lhames
> Date: Tue Jun 20 16:30:43 2017
> New Revision: 305860
>
> URL: http://llvm.org/viewvc/llvm-project?rev=305860=rev
> Log:
> Special-case handling of destructors in override lists when dumping ASTs.
>
> Fixes a bug in r305850: CXXDestructors don't have names, so we need to
> handle
> printing of them separately.
>

Clang models destructors as having names, and should print them properly.
What was actually going wrong here? There are other kinds of name that can
be virtual and aren't simple identifiers...


> Modified:
> cfe/trunk/lib/AST/ASTDumper.cpp
>
> Modified: cfe/trunk/lib/AST/ASTDumper.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/
> ASTDumper.cpp?rev=305860=305859=305860=diff
> 
> ==
> --- cfe/trunk/lib/AST/ASTDumper.cpp (original)
> +++ cfe/trunk/lib/AST/ASTDumper.cpp Tue Jun 20 16:30:43 2017
> @@ -1189,9 +1189,12 @@ void ASTDumper::VisitFunctionDecl(const
>auto dumpOverride =
>  [=](const CXXMethodDecl *D) {
>SplitQualType T_split = D->getType().split();
> -  OS << D << " " << D->getParent()->getName() << "::"
> - << D->getName() << " '"
> - << QualType::getAsString(T_split) << "'";
> +  OS << D << " " << D->getParent()->getName() << "::";
> +  if (isa(D))
> +OS << "~" << D->getParent()->getName();
> +  else
> +OS << D->getName();
> +  OS << " '" << QualType::getAsString(T_split) << "'";
>  };
>
>dumpChild([=] {
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34425: Unified ARM logic for computing target ABI.

2017-06-20 Thread Ana Pazos via Phabricator via cfe-commits
apazos created this revision.
Herald added subscribers: kristof.beyls, javed.absar, srhines, aemerson.

Unified logic for computing target ABI in backend and front end by moving this 
common code to Support/TargetParser.

Modeled Triple::GNU after front end code (aapcs abi) and  updated tests that 
expect apcs abi.

Removed assertion in backend to avoid different compiler behavior due to build 
mode.


https://reviews.llvm.org/D34425

Files:
  lib/Driver/ToolChains/Clang.cpp
  test/CodeGen/arm-v8.1a-neon-intrinsics.c
  test/CodeGen/named_reg_global.c
  test/CodeGen/neon-immediate-ubsan.c
  test/CodeGen/xray-attributes-supported.cpp

Index: test/CodeGen/xray-attributes-supported.cpp
===
--- test/CodeGen/xray-attributes-supported.cpp
+++ test/CodeGen/xray-attributes-supported.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 %s -fxray-instrument -std=c++11 -x c++ -emit-llvm -o - -triple x86_64-unknown-linux-gnu | FileCheck %s
-// RUN: %clang_cc1 %s -fxray-instrument -std=c++11 -x c++ -emit-llvm -o - -triple arm-unknown-linux-gnu | FileCheck %s
+// RUN: %clang_cc1 %s -fxray-instrument -std=c++11 -x c++ -emit-llvm -o - -triple arm-unknown-linux-gnu -target-abi apcs-gnu | FileCheck %s
 // RUN: %clang_cc1 %s -fxray-instrument -std=c++11 -x c++ -emit-llvm -o - -triple mips-unknown-linux-gnu | FileCheck %s
 // RUN: %clang_cc1 %s -fxray-instrument -std=c++11 -x c++ -emit-llvm -o - -triple mipsel-unknown-linux-gnu | FileCheck %s
 // RUN: %clang_cc1 %s -fxray-instrument -std=c++11 -x c++ -emit-llvm -o - -triple mips64-unknown-linux-gnu | FileCheck %s
Index: test/CodeGen/neon-immediate-ubsan.c
===
--- test/CodeGen/neon-immediate-ubsan.c
+++ test/CodeGen/neon-immediate-ubsan.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple armv7s-linux-gnu -emit-llvm -o - %s \
+// RUN: %clang_cc1 -triple armv7s-linux-gnu -target-abi apcs-gnu -emit-llvm -o - %s \
 // RUN: -target-feature +neon -target-cpu cortex-a8 \
 // RUN: -fsanitize=signed-integer-overflow \
 // RUN:   | FileCheck %s --check-prefix=CHECK --check-prefix=ARMV7
Index: test/CodeGen/named_reg_global.c
===
--- test/CodeGen/named_reg_global.c
+++ test/CodeGen/named_reg_global.c
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -S -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-X86-64
 // RUN: %clang_cc1 -triple arm64-linux-gnu -S -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-ARM
-// RUN: %clang_cc1 -triple armv7-linux-gnu -S -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-ARM
+// RUN: %clang_cc1 -triple armv7-linux-gnu -target-abi apcs-gnu -S -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-ARM
 
 // CHECK-NOT: @sp = common global
 
Index: test/CodeGen/arm-v8.1a-neon-intrinsics.c
===
--- test/CodeGen/arm-v8.1a-neon-intrinsics.c
+++ test/CodeGen/arm-v8.1a-neon-intrinsics.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple armv8.1a-linux-gnu -target-feature +neon \
+// RUN: %clang_cc1 -triple armv8.1a-linux-gnu -target-abi apcs-gnu -target-feature +neon \
 // RUN:  -S -emit-llvm -o - %s \
 // RUN:  | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-ARM
 
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -35,6 +35,7 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
+#include "llvm/Support/TargetParser.h"
 #include "llvm/Support/YAMLParser.h"
 
 #ifdef LLVM_ON_UNIX
@@ -1278,43 +1279,13 @@
   // FIXME: Support -meabi.
   // FIXME: Parts of this are duplicated in the backend, unify this somehow.
   const char *ABIName = nullptr;
-  if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) {
+  if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ))
 ABIName = A->getValue();
-  } else if (Triple.isOSBinFormatMachO()) {
-if (arm::useAAPCSForMachO(Triple)) {
-  ABIName = "aapcs";
-} else if (Triple.isWatchABI()) {
-  ABIName = "aapcs16";
-} else {
-  ABIName = "apcs-gnu";
-}
-  } else if (Triple.isOSWindows()) {
-// FIXME: this is invalid for WindowsCE
-ABIName = "aapcs";
-  } else {
-// Select the default based on the platform.
-switch (Triple.getEnvironment()) {
-case llvm::Triple::Android:
-case llvm::Triple::GNUEABI:
-case llvm::Triple::GNUEABIHF:
-case llvm::Triple::MuslEABI:
-case llvm::Triple::MuslEABIHF:
-  ABIName = "aapcs-linux";
-  break;
-case llvm::Triple::EABIHF:
-case llvm::Triple::EABI:
-  ABIName = "aapcs";
-  break;
-default:
-  if (Triple.getOS() == llvm::Triple::NetBSD)
-ABIName = "apcs-gnu";
-  else if 

[PATCH] D34304: Allow CompilerInvocations to generate .d files.

2017-06-20 Thread Sterling Augustine via Phabricator via cfe-commits
saugustine added a comment.

In https://reviews.llvm.org/D34304#785083, @klimek wrote:

> I think it's cleaner, because it uses a concept we already have (argument 
> adapters).


Will you point me to an example of these. Google is coming up empty.


https://reviews.llvm.org/D34304



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


[PATCH] D22057: Prevent devirtualization of calls to un-instantiated functions.

2017-06-20 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL305862: Prevent devirtualization of calls to un-instantiated 
functions. (authored by ssrivastava).

Changed prior to commit:
  https://reviews.llvm.org/D22057?vs=71432=103273#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D22057

Files:
  cfe/trunk/include/clang/AST/Decl.h
  cfe/trunk/lib/CodeGen/CGClass.cpp
  cfe/trunk/lib/Sema/Sema.cpp
  cfe/trunk/lib/Sema/SemaExpr.cpp
  cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
  cfe/trunk/test/CodeGen/no-devirt.cpp

Index: cfe/trunk/include/clang/AST/Decl.h
===
--- cfe/trunk/include/clang/AST/Decl.h
+++ cfe/trunk/include/clang/AST/Decl.h
@@ -1656,6 +1656,7 @@
   unsigned HasImplicitReturnZero : 1;
   unsigned IsLateTemplateParsed : 1;
   unsigned IsConstexpr : 1;
+  unsigned InstantiationIsPending:1;
 
   /// \brief Indicates if the function uses __try.
   unsigned UsesSEHTry : 1;
@@ -1751,6 +1752,7 @@
 IsDeleted(false), IsTrivial(false), IsDefaulted(false),
 IsExplicitlyDefaulted(false), HasImplicitReturnZero(false),
 IsLateTemplateParsed(false), IsConstexpr(isConstexprSpecified),
+InstantiationIsPending(false),
 UsesSEHTry(false), HasSkippedBody(false), WillHaveBody(false),
 EndRangeLoc(NameInfo.getEndLoc()), TemplateOrSpecialization(),
 DNLoc(NameInfo.getInfo()) {}
@@ -1943,6 +1945,15 @@
   bool isConstexpr() const { return IsConstexpr; }
   void setConstexpr(bool IC) { IsConstexpr = IC; }
 
+  /// \brief Whether the instantiation of this function is pending.
+  /// This bit is set when the decision to instantiate this function is made
+  /// and unset if and when the function body is created. That leaves out
+  /// cases where instantiation did not happen because the template definition
+  /// was not seen in this TU. This bit remains set in those cases, under the
+  /// assumption that the instantiation will happen in some other TU.
+  bool instantiationIsPending() const { return InstantiationIsPending; }
+  void setInstantiationIsPending(bool IC) { InstantiationIsPending = IC; }
+
   /// \brief Indicates the function uses __try.
   bool usesSEHTry() const { return UsesSEHTry; }
   void setUsesSEHTry(bool UST) { UsesSEHTry = UST; }
Index: cfe/trunk/test/CodeGen/no-devirt.cpp
===
--- cfe/trunk/test/CodeGen/no-devirt.cpp
+++ cfe/trunk/test/CodeGen/no-devirt.cpp
@@ -0,0 +1,59 @@
+// RUN: %clang_cc1 %s -DUSEIT -triple %itanium_abi_triple -emit-llvm -o - |  FileCheck %s
+
+// Test with decls and template defs in pch, and just use in .cpp
+// RUN:  %clang_cc1 %s -DTMPL_DEF_IN_HEADER -triple %itanium_abi_triple -emit-pch -o %t
+// RUN:  %clang_cc1 %s -DTMPL_DEF_IN_HEADER -DUSEIT -triple %itanium_abi_triple -include-pch %t -emit-llvm -o - | FileCheck %s
+
+// Test with A in pch, and B and C in main
+// Test with just decls in pch, and template defs and use in .cpp
+// RUN:  %clang_cc1 %s -triple %itanium_abi_triple -emit-pch -o %t
+// RUN:  %clang_cc1 %s -DUSEIT -triple %itanium_abi_triple -include-pch %t -emit-llvm -o - | FileCheck %s
+
+#ifndef HEADER
+#define HEADER
+template < typename T, int N = 0 > class TmplWithArray {
+public:
+  virtual T& operator [] (int idx);
+  virtual T& func1 (int idx);
+  virtual T& func2 (int idx);
+  T ar[N+1];
+};
+struct Wrapper {
+  TmplWithArray data;
+  bool indexIt(int a) {
+if (a > 6) return data[a] ;  // Should not devirtualize
+if (a > 4) return data.func1(a); // Should devirtualize
+return data.func2(a);// Should devirtualize
+  }
+};
+
+#ifdef TMPL_DEF_IN_HEADER
+template  T& TmplWithArray::operator[](int idx) {
+  return ar[idx];
+}
+template  T& TmplWithArray::func1(int idx) {
+  return ar[idx];
+}
+#endif // TMPL_DEF_IN_HEADER
+#endif // HEADER
+
+#ifdef USEIT
+#ifndef TMPL_DEF_IN_HEADER
+template  T& TmplWithArray::operator[](int idx) {
+  return ar[idx];
+}
+template  T& TmplWithArray::func1(int idx) {
+  return ar[idx];
+}
+#endif // !TMPL_DEF_IN_HEADER
+extern Wrapper ew;
+bool stuff(int p)
+{
+  return ew.indexIt(p);
+}
+#endif
+
+// CHECK-NOT: call {{.*}} @_ZN13TmplWithArrayIbLi10EEixEi
+// CHECK-DAG: call {{.*}} @_ZN13TmplWithArrayIbLi10EE5func1Ei
+// CHECK-DAG: call {{.*}} @_ZN13TmplWithArrayIbLi10EE5func2Ei
+
Index: cfe/trunk/lib/Sema/Sema.cpp
===
--- cfe/trunk/lib/Sema/Sema.cpp
+++ cfe/trunk/lib/Sema/Sema.cpp
@@ -740,6 +740,9 @@
   // Load pending instantiations from the external source.
   SmallVector Pending;
   ExternalSource->ReadPendingInstantiations(Pending);
+  for (auto PII : Pending)
+if (auto Func = dyn_cast(PII.first))
+  Func->setInstantiationIsPending(true);
   

r305862 - Prevent devirtualization of calls to un-instantiated functions.

2017-06-20 Thread Sunil Srivastava via cfe-commits
Author: ssrivastava
Date: Tue Jun 20 17:08:44 2017
New Revision: 305862

URL: http://llvm.org/viewvc/llvm-project?rev=305862=rev
Log:
Prevent devirtualization of calls to un-instantiated functions.

PR 27895

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

Added:
cfe/trunk/test/CodeGen/no-devirt.cpp
Modified:
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/lib/CodeGen/CGClass.cpp
cfe/trunk/lib/Sema/Sema.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=305862=305861=305862=diff
==
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Tue Jun 20 17:08:44 2017
@@ -1656,6 +1656,7 @@ private:
   unsigned HasImplicitReturnZero : 1;
   unsigned IsLateTemplateParsed : 1;
   unsigned IsConstexpr : 1;
+  unsigned InstantiationIsPending:1;
 
   /// \brief Indicates if the function uses __try.
   unsigned UsesSEHTry : 1;
@@ -1751,6 +1752,7 @@ protected:
 IsDeleted(false), IsTrivial(false), IsDefaulted(false),
 IsExplicitlyDefaulted(false), HasImplicitReturnZero(false),
 IsLateTemplateParsed(false), IsConstexpr(isConstexprSpecified),
+InstantiationIsPending(false),
 UsesSEHTry(false), HasSkippedBody(false), WillHaveBody(false),
 EndRangeLoc(NameInfo.getEndLoc()), TemplateOrSpecialization(),
 DNLoc(NameInfo.getInfo()) {}
@@ -1943,6 +1945,15 @@ public:
   bool isConstexpr() const { return IsConstexpr; }
   void setConstexpr(bool IC) { IsConstexpr = IC; }
 
+  /// \brief Whether the instantiation of this function is pending.
+  /// This bit is set when the decision to instantiate this function is made
+  /// and unset if and when the function body is created. That leaves out
+  /// cases where instantiation did not happen because the template definition
+  /// was not seen in this TU. This bit remains set in those cases, under the
+  /// assumption that the instantiation will happen in some other TU.
+  bool instantiationIsPending() const { return InstantiationIsPending; }
+  void setInstantiationIsPending(bool IC) { InstantiationIsPending = IC; }
+
   /// \brief Indicates the function uses __try.
   bool usesSEHTry() const { return UsesSEHTry; }
   void setUsesSEHTry(bool UST) { UsesSEHTry = UST; }

Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=305862=305861=305862=diff
==
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Tue Jun 20 17:08:44 2017
@@ -2770,10 +2770,19 @@ CodeGenFunction::CanDevirtualizeMemberFu
 
   // We can devirtualize calls on an object accessed by a class member access
   // expression, since by C++11 [basic.life]p6 we know that it can't refer to
-  // a derived class object constructed in the same location.
+  // a derived class object constructed in the same location. However, we avoid
+  // devirtualizing a call to a template function that we could instantiate
+  // implicitly, but have not decided to do so. This is needed because if this
+  // function does not get instantiated, the devirtualization will create a
+  // direct call to a function whose body may not exist. In contrast, calls to
+  // template functions that are not defined in this TU are allowed to be 
+  // devirtualized under assumption that it is user responsibility to
+  // instantiate them in some other TU.
   if (const MemberExpr *ME = dyn_cast(Base))
 if (const ValueDecl *VD = dyn_cast(ME->getMemberDecl()))
-  return VD->getType()->isRecordType();
+  return VD->getType()->isRecordType() && 
+ (MD->instantiationIsPending() || MD->isDefined() ||
+   !MD->isImplicitlyInstantiable());
 
   // Likewise for calls on an object accessed by a (non-reference) pointer to
   // member access.

Modified: cfe/trunk/lib/Sema/Sema.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=305862=305861=305862=diff
==
--- cfe/trunk/lib/Sema/Sema.cpp (original)
+++ cfe/trunk/lib/Sema/Sema.cpp Tue Jun 20 17:08:44 2017
@@ -740,6 +740,9 @@ void Sema::ActOnEndOfTranslationUnit() {
   // Load pending instantiations from the external source.
   SmallVector Pending;
   ExternalSource->ReadPendingInstantiations(Pending);
+  for (auto PII : Pending)
+if (auto Func = dyn_cast(PII.first))
+  Func->setInstantiationIsPending(true);
   PendingInstantiations.insert(PendingInstantiations.begin(),
Pending.begin(), Pending.end());
 }

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 

[PATCH] D33620: [CodeGenCXX] do not default to dllimport storage for mingw-w64

2017-06-20 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

Saleem, didn't something change here two months ago? Why do we want to bother 
with all of this dllimport stuff in the frontend? It seems to break mingw and 
add complexity for very little gain (avoiding linker provided thunks).


Repository:
  rL LLVM

https://reviews.llvm.org/D33620



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


[PATCH] D33499: [PPC] PPC32/Darwin ABI info

2017-06-20 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai added subscribers: iains, echristo.
nemanjai added a comment.

I'm not sure how much expertise there is for PPC32-Darwin. Perhaps @iains might 
be able to offer some insight here. Also, @echristo might have a thing or two 
to say in this regard.


Repository:
  rL LLVM

https://reviews.llvm.org/D33499



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


r305860 - Special-case handling of destructors in override lists when dumping ASTs.

2017-06-20 Thread Lang Hames via cfe-commits
Author: lhames
Date: Tue Jun 20 16:30:43 2017
New Revision: 305860

URL: http://llvm.org/viewvc/llvm-project?rev=305860=rev
Log:
Special-case handling of destructors in override lists when dumping ASTs.

Fixes a bug in r305850: CXXDestructors don't have names, so we need to handle
printing of them separately.


Modified:
cfe/trunk/lib/AST/ASTDumper.cpp

Modified: cfe/trunk/lib/AST/ASTDumper.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTDumper.cpp?rev=305860=305859=305860=diff
==
--- cfe/trunk/lib/AST/ASTDumper.cpp (original)
+++ cfe/trunk/lib/AST/ASTDumper.cpp Tue Jun 20 16:30:43 2017
@@ -1189,9 +1189,12 @@ void ASTDumper::VisitFunctionDecl(const
   auto dumpOverride =
 [=](const CXXMethodDecl *D) {
   SplitQualType T_split = D->getType().split();
-  OS << D << " " << D->getParent()->getName() << "::"
- << D->getName() << " '"
- << QualType::getAsString(T_split) << "'";
+  OS << D << " " << D->getParent()->getName() << "::";
+  if (isa(D))
+OS << "~" << D->getParent()->getName();
+  else
+OS << D->getName();
+  OS << " '" << QualType::getAsString(T_split) << "'";
 };
 
   dumpChild([=] {


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


[PATCH] D34377: Support MS builtins using 'long' on Darwin/LP64

2017-06-20 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno added inline comments.



Comment at: lib/AST/ASTContext.cpp:8551
+  break;
+}
 case 'W':

bruno wrote:
> rnk wrote:
> > majnemer wrote:
> > > bruno wrote:
> > > > bruno wrote:
> > > > > rnk wrote:
> > > > > > compnerd wrote:
> > > > > > > I agree with @majnemer.  Why not base this on the Int64Type?
> > > > > > I'd suggest this code:
> > > > > >   IsSpecialLong = true;
> > > > > >   // Use "long" if is 32 bits. This prefix is used by intrinsics 
> > > > > > that need 32-bit types on LP64 platforms, but need to use "long" in 
> > > > > > the prototype on LLP64 platforms like Win64.
> > > > > >   if (Context.getTargetInfo().getLongWidth() == 32)
> > > > > > HowLong = 1;
> > > > > >   break;
> > > > > See below.
> > > > I tried something similar before, but I get two tests failing 
> > > > CodeGen/ms-intrinsics-rotations.c and CodeGen/pr27892.c. Your 
> > > > suggestion hits the same failing tests. Both fails because of the Linux 
> > > > issue mentioned above: i32 codegen where i64 is expected. Of course I 
> > > > could improve the condition to handle Linux, but at that point I just 
> > > > thing it's better to use Darwin, which is what the fix is towards 
> > > > anyway. Additional ideas?
> > > I don't think we should sweep this under the rug just because there are 
> > > some test failures. There is probably some latent bug worth investigating.
> > I think I remember answer a question for Albert during his internship, and 
> > I said something like "they should stay longs", so he added those tests. 
> > Thinking about it now, those test should be changed to expect 32-bit ints.
> Well, there's specific testing for this behavior under Linux, so I assume 
> someone needs this? I don't see how this is sweeping stuff under the rug.
---
Oh, I see. Gonna rework those then!


https://reviews.llvm.org/D34377



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


[PATCH] D34377: Support MS builtins using 'long' on Darwin/LP64

2017-06-20 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added inline comments.



Comment at: lib/AST/ASTContext.cpp:8551
+  break;
+}
 case 'W':

majnemer wrote:
> bruno wrote:
> > bruno wrote:
> > > rnk wrote:
> > > > compnerd wrote:
> > > > > I agree with @majnemer.  Why not base this on the Int64Type?
> > > > I'd suggest this code:
> > > >   IsSpecialLong = true;
> > > >   // Use "long" if is 32 bits. This prefix is used by intrinsics that 
> > > > need 32-bit types on LP64 platforms, but need to use "long" in the 
> > > > prototype on LLP64 platforms like Win64.
> > > >   if (Context.getTargetInfo().getLongWidth() == 32)
> > > > HowLong = 1;
> > > >   break;
> > > See below.
> > I tried something similar before, but I get two tests failing 
> > CodeGen/ms-intrinsics-rotations.c and CodeGen/pr27892.c. Your suggestion 
> > hits the same failing tests. Both fails because of the Linux issue 
> > mentioned above: i32 codegen where i64 is expected. Of course I could 
> > improve the condition to handle Linux, but at that point I just thing it's 
> > better to use Darwin, which is what the fix is towards anyway. Additional 
> > ideas?
> I don't think we should sweep this under the rug just because there are some 
> test failures. There is probably some latent bug worth investigating.
I think I remember answer a question for Albert during his internship, and I 
said something like "they should stay longs", so he added those tests. Thinking 
about it now, those test should be changed to expect 32-bit ints.


https://reviews.llvm.org/D34377



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


[PATCH] D34377: Support MS builtins using 'long' on Darwin/LP64

2017-06-20 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno added inline comments.



Comment at: lib/AST/ASTContext.cpp:8551
+  break;
+}
 case 'W':

majnemer wrote:
> bruno wrote:
> > bruno wrote:
> > > rnk wrote:
> > > > compnerd wrote:
> > > > > I agree with @majnemer.  Why not base this on the Int64Type?
> > > > I'd suggest this code:
> > > >   IsSpecialLong = true;
> > > >   // Use "long" if is 32 bits. This prefix is used by intrinsics that 
> > > > need 32-bit types on LP64 platforms, but need to use "long" in the 
> > > > prototype on LLP64 platforms like Win64.
> > > >   if (Context.getTargetInfo().getLongWidth() == 32)
> > > > HowLong = 1;
> > > >   break;
> > > See below.
> > I tried something similar before, but I get two tests failing 
> > CodeGen/ms-intrinsics-rotations.c and CodeGen/pr27892.c. Your suggestion 
> > hits the same failing tests. Both fails because of the Linux issue 
> > mentioned above: i32 codegen where i64 is expected. Of course I could 
> > improve the condition to handle Linux, but at that point I just thing it's 
> > better to use Darwin, which is what the fix is towards anyway. Additional 
> > ideas?
> I don't think we should sweep this under the rug just because there are some 
> test failures. There is probably some latent bug worth investigating.
Well, there's specific testing for this behavior under Linux, so I assume 
someone needs this? I don't see how this is sweeping stuff under the rug.


https://reviews.llvm.org/D34377



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


Re: r305850 - Preserve CXX method overrides in ASTImporter

2017-06-20 Thread Lang Hames via cfe-commits
Oops - this broke Sema/ms_class_layout.cpp. Looking in to it now...

- Lang.

On Tue, Jun 20, 2017 at 2:06 PM, Lang Hames via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: lhames
> Date: Tue Jun 20 16:06:00 2017
> New Revision: 305850
>
> URL: http://llvm.org/viewvc/llvm-project?rev=305850=rev
> Log:
> Preserve CXX method overrides in ASTImporter
>
> Summary:
> The ASTImporter should import CXX method overrides from the source context
> when it imports a method decl.
>
> Reviewers: spyffe, rsmith, doug.gregor
>
> Reviewed By: spyffe
>
> Differential Revision: https://reviews.llvm.org/D34371
>
> Modified:
> cfe/trunk/lib/AST/ASTDumper.cpp
> cfe/trunk/lib/AST/ASTImporter.cpp
> cfe/trunk/tools/clang-import-test/clang-import-test.cpp
>
> Modified: cfe/trunk/lib/AST/ASTDumper.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/
> ASTDumper.cpp?rev=305850=305849=305850=diff
> 
> ==
> --- cfe/trunk/lib/AST/ASTDumper.cpp (original)
> +++ cfe/trunk/lib/AST/ASTDumper.cpp Tue Jun 20 16:06:00 2017
> @@ -1184,6 +1184,28 @@ void ASTDumper::VisitFunctionDecl(const
>   I != E; ++I)
>dumpCXXCtorInitializer(*I);
>
> +  if (const CXXMethodDecl *MD = dyn_cast(D))
> +if (MD->size_overridden_methods() != 0) {
> +  auto dumpOverride =
> +[=](const CXXMethodDecl *D) {
> +  SplitQualType T_split = D->getType().split();
> +  OS << D << " " << D->getParent()->getName() << "::"
> + << D->getName() << " '"
> + << QualType::getAsString(T_split) << "'";
> +};
> +
> +  dumpChild([=] {
> +auto FirstOverrideItr = MD->begin_overridden_methods();
> +OS << "Overrides: [ ";
> +dumpOverride(*FirstOverrideItr);
> +for (const auto *Override :
> +   llvm::make_range(FirstOverrideItr + 1,
> +MD->end_overridden_methods()))
> +  dumpOverride(Override);
> +OS << " ]";
> +  });
> +}
> +
>if (D->doesThisDeclarationHaveABody())
>  dumpStmt(D->getBody());
>  }
>
> Modified: cfe/trunk/lib/AST/ASTImporter.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/
> ASTImporter.cpp?rev=305850=305849=305850=diff
> 
> ==
> --- cfe/trunk/lib/AST/ASTImporter.cpp (original)
> +++ cfe/trunk/lib/AST/ASTImporter.cpp Tue Jun 20 16:06:00 2017
> @@ -319,6 +319,9 @@ namespace clang {
>  bool ImportArrayChecked(const InContainerTy , OIter
> Obegin) {
>return ImportArrayChecked(InContainer.begin(), InContainer.end(),
> Obegin);
>  }
> +
> +// Importing overrides.
> +void ImportOverrides(CXXMethodDecl *ToMethod, CXXMethodDecl
> *FromMethod);
>};
>  }
>
> @@ -2025,6 +2028,9 @@ Decl *ASTNodeImporter::VisitFunctionDecl
>// Add this function to the lexical context.
>LexicalDC->addDeclInternal(ToFunction);
>
> +  if (auto *FromCXXMethod = dyn_cast(D))
> +ImportOverrides(cast(ToFunction), FromCXXMethod);
> +
>return ToFunction;
>  }
>
> @@ -5499,6 +5505,14 @@ Expr *ASTNodeImporter::VisitSubstNonType
>  Replacement);
>  }
>
> +void ASTNodeImporter::ImportOverrides(CXXMethodDecl *ToMethod,
> +  CXXMethodDecl *FromMethod) {
> +  for (auto *FromOverriddenMethod : FromMethod->overridden_methods())
> +ToMethod->addOverriddenMethod(
> +  cast(Importer.Import(const_cast(
> +FromOverriddenMethod;
> +}
> +
>  ASTImporter::ASTImporter(ASTContext , FileManager
> ,
>   ASTContext , FileManager
> ,
>   bool MinimalImport)
>
> Modified: cfe/trunk/tools/clang-import-test/clang-import-test.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-
> import-test/clang-import-test.cpp?rev=305850=305849=305850=diff
> 
> ==
> --- cfe/trunk/tools/clang-import-test/clang-import-test.cpp (original)
> +++ cfe/trunk/tools/clang-import-test/clang-import-test.cpp Tue Jun 20
> 16:06:00 2017
> @@ -17,7 +17,9 @@
>  #include "clang/Basic/TargetInfo.h"
>  #include "clang/Basic/TargetOptions.h"
>  #include "clang/CodeGen/ModuleBuilder.h"
> +#include "clang/Frontend/ASTConsumers.h"
>  #include "clang/Frontend/CompilerInstance.h"
> +#include "clang/Frontend/MultiplexConsumer.h"
>  #include "clang/Frontend/TextDiagnosticBuffer.h"
>  #include "clang/Lex/Lexer.h"
>  #include "clang/Lex/Preprocessor.h"
> @@ -51,6 +53,10 @@ static llvm::cl::list
>llvm::cl::desc("Argument to pass to the
> CompilerInvocation"),
>llvm::cl::CommaSeparated);
>
> +static llvm::cl::opt
> +DumpAST("dump-ast", llvm::cl::init(false),
> +llvm::cl::desc("Dump combined AST"));
> +
>  namespace init_convenience {
>  class 

[PATCH] D34377: Support MS builtins using 'long' on Darwin/LP64

2017-06-20 Thread David Majnemer via Phabricator via cfe-commits
majnemer added inline comments.



Comment at: lib/AST/ASTContext.cpp:8551
+  break;
+}
 case 'W':

bruno wrote:
> bruno wrote:
> > rnk wrote:
> > > compnerd wrote:
> > > > I agree with @majnemer.  Why not base this on the Int64Type?
> > > I'd suggest this code:
> > >   IsSpecialLong = true;
> > >   // Use "long" if is 32 bits. This prefix is used by intrinsics that 
> > > need 32-bit types on LP64 platforms, but need to use "long" in the 
> > > prototype on LLP64 platforms like Win64.
> > >   if (Context.getTargetInfo().getLongWidth() == 32)
> > > HowLong = 1;
> > >   break;
> > See below.
> I tried something similar before, but I get two tests failing 
> CodeGen/ms-intrinsics-rotations.c and CodeGen/pr27892.c. Your suggestion hits 
> the same failing tests. Both fails because of the Linux issue mentioned 
> above: i32 codegen where i64 is expected. Of course I could improve the 
> condition to handle Linux, but at that point I just thing it's better to use 
> Darwin, which is what the fix is towards anyway. Additional ideas?
I don't think we should sweep this under the rug just because there are some 
test failures. There is probably some latent bug worth investigating.


https://reviews.llvm.org/D34377



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


[libcxx] r305854 - [libcxx] [test] Fix -Wmismatched-tags in tuple_size_structured_bindings.pass.cpp.

2017-06-20 Thread Stephan T. Lavavej via cfe-commits
Author: stl_msft
Date: Tue Jun 20 16:10:53 2017
New Revision: 305854

URL: http://llvm.org/viewvc/llvm-project?rev=305854=rev
Log:
[libcxx] [test] Fix -Wmismatched-tags in 
tuple_size_structured_bindings.pass.cpp.

Clang and C1XX both complain about mismatched class/struct, but libc++ and 
MSVC's STL
differ on what they use for tuple_element/tuple_size, so there's no way to win 
here.

I'm reverting this part of my previous change. In the future, I'll have to 
suppress
the warning for one compiler or the other.

Modified:

libcxx/trunk/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_structured_bindings.pass.cpp

Modified: 
libcxx/trunk/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_structured_bindings.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_structured_bindings.pass.cpp?rev=305854=305853=305854=diff
==
--- 
libcxx/trunk/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_structured_bindings.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_structured_bindings.pass.cpp
 Tue Jun 20 16:10:53 2017
@@ -117,7 +117,8 @@ template 
 int get(Test const&) { static_assert(N == 0, ""); return -1; }
 
 template <>
-struct std::tuple_element<0, Test> {
+class std::tuple_element<0, Test> {
+public:
   typedef int type;
 };
 
@@ -128,7 +129,8 @@ void test_before_tuple_size_specializati
 }
 
 template <>
-struct std::tuple_size {
+class std::tuple_size {
+public:
   static const size_t value = 1;
 };
 


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


[PATCH] D34419: Make sure TraverseInitListExpr visits InitListExpr exactly twice

2017-06-20 Thread Stephan Bergmann via Phabricator via cfe-commits
sberg created this revision.

... once each for the syntactic and semantic form. Without this fix, behavior 
of the newly added tests would have been

InitListExprIsPreOrderVisitedTwice:
 syntactic: 1
 semantic:  2

InitListExprIsPostOrderVisitedTwice:
 syntactic: 0
 semantic:  1

InitListExprIsPreOrderNoQueueVisitedTwice:
 syntactic: 1
 semantic:  2

InitListExprIsPostOrderNoQueueVisitedTwice:
 syntactic: 0
 semantic:  2


https://reviews.llvm.org/D34419

Files:
  include/clang/AST/RecursiveASTVisitor.h
  unittests/Tooling/RecursiveASTVisitorTest.cpp

Index: unittests/Tooling/RecursiveASTVisitorTest.cpp
===
--- unittests/Tooling/RecursiveASTVisitorTest.cpp
+++ unittests/Tooling/RecursiveASTVisitorTest.cpp
@@ -158,4 +158,90 @@
   "static int k = f();\n"));
 }
 
+// Check to ensure that InitListExpr is visited twice, once each for the
+// syntactic and semantic form.
+class InitListExprPreOrderVisitor
+: public ExpectedLocationVisitor {
+public:
+  bool VisitInitListExpr(InitListExpr *ILE) {
+Match(ILE->isSemanticForm() ? "semantic" : "syntactic", ILE->getLocStart());
+return true;
+  }
+};
+
+class InitListExprPostOrderVisitor
+: public ExpectedLocationVisitor {
+public:
+  bool shouldTraversePostOrder() const { return true; }
+
+  bool VisitInitListExpr(InitListExpr *ILE) {
+Match(ILE->isSemanticForm() ? "semantic" : "syntactic", ILE->getLocStart());
+return true;
+  }
+};
+
+class InitListExprPreOrderNoQueueVisitor
+: public ExpectedLocationVisitor {
+public:
+  bool TraverseInitListExpr(InitListExpr *ILE) {
+return ExpectedLocationVisitor::TraverseInitListExpr(ILE);
+  }
+
+  bool VisitInitListExpr(InitListExpr *ILE) {
+Match(ILE->isSemanticForm() ? "semantic" : "syntactic", ILE->getLocStart());
+return true;
+  }
+};
+
+class InitListExprPostOrderNoQueueVisitor
+: public ExpectedLocationVisitor {
+public:
+  bool shouldTraversePostOrder() const { return true; }
+
+  bool TraverseInitListExpr(InitListExpr *ILE) {
+return ExpectedLocationVisitor::TraverseInitListExpr(ILE);
+  }
+
+  bool VisitInitListExpr(InitListExpr *ILE) {
+Match(ILE->isSemanticForm() ? "semantic" : "syntactic", ILE->getLocStart());
+return true;
+  }
+};
+
+TEST(RecursiveASTVisitor, InitListExprIsPreOrderVisitedTwice) {
+  InitListExprPreOrderVisitor Visitor;
+  Visitor.ExpectMatch("syntactic", 2, 21);
+  Visitor.ExpectMatch("semantic", 2, 21);
+  EXPECT_TRUE(Visitor.runOver("struct S { int x; };\n"
+  "static struct S s = {.x = 0};\n",
+  InitListExprPreOrderVisitor::Lang_C));
+}
+
+TEST(RecursiveASTVisitor, InitListExprIsPostOrderVisitedTwice) {
+  InitListExprPostOrderVisitor Visitor;
+  Visitor.ExpectMatch("syntactic", 2, 21);
+  Visitor.ExpectMatch("semantic", 2, 21);
+  EXPECT_TRUE(Visitor.runOver("struct S { int x; };\n"
+  "static struct S s = {.x = 0};\n",
+  InitListExprPostOrderVisitor::Lang_C));
+}
+
+TEST(RecursiveASTVisitor, InitListExprIsPreOrderNoQueueVisitedTwice) {
+  InitListExprPreOrderNoQueueVisitor Visitor;
+  Visitor.ExpectMatch("syntactic", 2, 21);
+  Visitor.ExpectMatch("semantic", 2, 21);
+  EXPECT_TRUE(Visitor.runOver("struct S { int x; };\n"
+  "static struct S s = {.x = 0};\n",
+  InitListExprPreOrderNoQueueVisitor::Lang_C));
+}
+
+TEST(RecursiveASTVisitor, InitListExprIsPostOrderNoQueueVisitedTwice) {
+  InitListExprPostOrderNoQueueVisitor Visitor;
+  Visitor.ExpectMatch("syntactic", 2, 21);
+  Visitor.ExpectMatch("semantic", 2, 21);
+  EXPECT_TRUE(Visitor.runOver("struct S { int x; };\n"
+  "static struct S s = {.x = 0};\n",
+  InitListExprPostOrderNoQueueVisitor::Lang_C));
+}
+
 } // end anonymous namespace
Index: include/clang/AST/RecursiveASTVisitor.h
===
--- include/clang/AST/RecursiveASTVisitor.h
+++ include/clang/AST/RecursiveASTVisitor.h
@@ -593,6 +593,16 @@
 #define STMT(CLASS, PARENT)\
   case Stmt::CLASS##Class: \
 TRY_TO(WalkUpFrom##CLASS(static_cast(S))); break;
+#define INITLISTEXPR(CLASS, PARENT)\
+  case Stmt::CLASS##Class: \
+{  \
+  auto ILE = static_cast(S);  \
+  if (auto Syn = ILE->isSemanticForm() ? ILE->getSyntacticForm() : ILE)\
+TRY_TO(WalkUpFrom##CLASS(Syn));\
+  if (auto Sem = ILE->isSemanticForm() ? ILE : ILE->getSemanticForm()) \
+TRY_TO(WalkUpFrom##CLASS(Sem));  

r305850 - Preserve CXX method overrides in ASTImporter

2017-06-20 Thread Lang Hames via cfe-commits
Author: lhames
Date: Tue Jun 20 16:06:00 2017
New Revision: 305850

URL: http://llvm.org/viewvc/llvm-project?rev=305850=rev
Log:
Preserve CXX method overrides in ASTImporter

Summary:
The ASTImporter should import CXX method overrides from the source context
when it imports a method decl.

Reviewers: spyffe, rsmith, doug.gregor

Reviewed By: spyffe

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

Modified:
cfe/trunk/lib/AST/ASTDumper.cpp
cfe/trunk/lib/AST/ASTImporter.cpp
cfe/trunk/tools/clang-import-test/clang-import-test.cpp

Modified: cfe/trunk/lib/AST/ASTDumper.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTDumper.cpp?rev=305850=305849=305850=diff
==
--- cfe/trunk/lib/AST/ASTDumper.cpp (original)
+++ cfe/trunk/lib/AST/ASTDumper.cpp Tue Jun 20 16:06:00 2017
@@ -1184,6 +1184,28 @@ void ASTDumper::VisitFunctionDecl(const
  I != E; ++I)
   dumpCXXCtorInitializer(*I);
 
+  if (const CXXMethodDecl *MD = dyn_cast(D))
+if (MD->size_overridden_methods() != 0) {
+  auto dumpOverride =
+[=](const CXXMethodDecl *D) {
+  SplitQualType T_split = D->getType().split();
+  OS << D << " " << D->getParent()->getName() << "::"
+ << D->getName() << " '"
+ << QualType::getAsString(T_split) << "'";
+};
+
+  dumpChild([=] {
+auto FirstOverrideItr = MD->begin_overridden_methods();
+OS << "Overrides: [ ";
+dumpOverride(*FirstOverrideItr);
+for (const auto *Override :
+   llvm::make_range(FirstOverrideItr + 1,
+MD->end_overridden_methods()))
+  dumpOverride(Override);
+OS << " ]";
+  });
+}
+
   if (D->doesThisDeclarationHaveABody())
 dumpStmt(D->getBody());
 }

Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=305850=305849=305850=diff
==
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Tue Jun 20 16:06:00 2017
@@ -319,6 +319,9 @@ namespace clang {
 bool ImportArrayChecked(const InContainerTy , OIter Obegin) {
   return ImportArrayChecked(InContainer.begin(), InContainer.end(), 
Obegin);
 }
+
+// Importing overrides.
+void ImportOverrides(CXXMethodDecl *ToMethod, CXXMethodDecl *FromMethod);
   };
 }
 
@@ -2025,6 +2028,9 @@ Decl *ASTNodeImporter::VisitFunctionDecl
   // Add this function to the lexical context.
   LexicalDC->addDeclInternal(ToFunction);
 
+  if (auto *FromCXXMethod = dyn_cast(D))
+ImportOverrides(cast(ToFunction), FromCXXMethod);
+
   return ToFunction;
 }
 
@@ -5499,6 +5505,14 @@ Expr *ASTNodeImporter::VisitSubstNonType
 Replacement);
 }
 
+void ASTNodeImporter::ImportOverrides(CXXMethodDecl *ToMethod,
+  CXXMethodDecl *FromMethod) {
+  for (auto *FromOverriddenMethod : FromMethod->overridden_methods())
+ToMethod->addOverriddenMethod(
+  cast(Importer.Import(const_cast(
+FromOverriddenMethod;
+}
+
 ASTImporter::ASTImporter(ASTContext , FileManager ,
  ASTContext , FileManager ,
  bool MinimalImport)

Modified: cfe/trunk/tools/clang-import-test/clang-import-test.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-import-test/clang-import-test.cpp?rev=305850=305849=305850=diff
==
--- cfe/trunk/tools/clang-import-test/clang-import-test.cpp (original)
+++ cfe/trunk/tools/clang-import-test/clang-import-test.cpp Tue Jun 20 16:06:00 
2017
@@ -17,7 +17,9 @@
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/TargetOptions.h"
 #include "clang/CodeGen/ModuleBuilder.h"
+#include "clang/Frontend/ASTConsumers.h"
 #include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/MultiplexConsumer.h"
 #include "clang/Frontend/TextDiagnosticBuffer.h"
 #include "clang/Lex/Lexer.h"
 #include "clang/Lex/Preprocessor.h"
@@ -51,6 +53,10 @@ static llvm::cl::list
   llvm::cl::desc("Argument to pass to the CompilerInvocation"),
   llvm::cl::CommaSeparated);
 
+static llvm::cl::opt
+DumpAST("dump-ast", llvm::cl::init(false),
+llvm::cl::desc("Dump combined AST"));
+
 namespace init_convenience {
 class TestDiagnosticConsumer : public DiagnosticConsumer {
 private:
@@ -233,7 +239,7 @@ std::unique_ptr BuildI
 }
 
 llvm::Error ParseSource(const std::string , CompilerInstance ,
-CodeGenerator ) {
+ASTConsumer ) {
   SourceManager  = CI.getSourceManager();
   const FileEntry *FE = CI.getFileManager().getFile(Path);
   if (!FE) {
@@ -241,13 +247,14 @@ llvm::Error ParseSource(const std::strin
   

[libcxx] r305848 - [libcxx] [test] Strip trailing whitespace. NFC.

2017-06-20 Thread Stephan T. Lavavej via cfe-commits
Author: stl_msft
Date: Tue Jun 20 16:00:02 2017
New Revision: 305848

URL: http://llvm.org/viewvc/llvm-project?rev=305848=rev
Log:
[libcxx] [test] Strip trailing whitespace. NFC.

Modified:

libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.foreach/for_each_n.pass.cpp

libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/advance.pass.cpp

libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/prev.pass.cpp

libcxx/trunk/test/std/numerics/numeric.ops/exclusive.scan/exclusive_scan.pass.cpp

libcxx/trunk/test/std/numerics/numeric.ops/exclusive.scan/exclusive_scan_init_op.pass.cpp
libcxx/trunk/test/std/numerics/numeric.ops/reduce/reduce_init_op.pass.cpp

libcxx/trunk/test/std/numerics/numeric.ops/transform.exclusive.scan/transform_exclusive_scan_init_bop_uop.pass.cpp

libcxx/trunk/test/std/numerics/numeric.ops/transform.reduce/transform_reduce_iter_iter_init_bop_uop.pass.cpp

libcxx/trunk/test/std/numerics/numeric.ops/transform.reduce/transform_reduce_iter_iter_iter_init.pass.cpp

libcxx/trunk/test/std/numerics/numeric.ops/transform.reduce/transform_reduce_iter_iter_iter_init_op_op.pass.cpp

libcxx/trunk/test/std/utilities/allocator.adaptor/allocator.adaptor.cnstr/allocs.pass.cpp

libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.ctor/move.pass.cpp
libcxx/trunk/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/dtor.pass.cpp
libcxx/trunk/test/std/utilities/utility/pairs/pairs.pair/dtor.pass.cpp

Modified: 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.foreach/for_each_n.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.foreach/for_each_n.pass.cpp?rev=305848=305847=305848=diff
==
--- 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.foreach/for_each_n.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.foreach/for_each_n.pass.cpp
 Tue Jun 20 16:00:02 2017
@@ -36,15 +36,15 @@ int main()
 auto f = for_each_test(0);
 Iter it = std::for_each_n(Iter(ia), 0, std::ref(f));
 assert(it == Iter(ia));
-assert(f.count == 0);
+assert(f.count == 0);
 }
 
 {
 auto f = for_each_test(0);
 Iter it = std::for_each_n(Iter(ia), s, std::ref(f));
-
+
 assert(it == Iter(ia+s));
-assert(f.count == s);
+assert(f.count == s);
 for (unsigned i = 0; i < s; ++i)
 assert(ia[i] == static_cast(i+1));
 }
@@ -52,9 +52,9 @@ int main()
 {
 auto f = for_each_test(0);
 Iter it = std::for_each_n(Iter(ia), 1, std::ref(f));
-
+
 assert(it == Iter(ia+1));
-assert(f.count == 1);
+assert(f.count == 1);
 for (unsigned i = 0; i < 1; ++i)
 assert(ia[i] == static_cast(i+2));
 }

Modified: 
libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/advance.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/advance.pass.cpp?rev=305848=305847=305848=diff
==
--- 
libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/advance.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/advance.pass.cpp
 Tue Jun 20 16:00:02 2017
@@ -35,7 +35,7 @@ test(It i, typename std::iterator_traits
 
 #if TEST_STD_VER > 14
 template 
-constexpr bool 
+constexpr bool
 constepxr_test(It i, typename std::iterator_traits::difference_type n, It 
x)
 {
 std::advance(i, n);

Modified: 
libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/prev.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/prev.pass.cpp?rev=305848=305847=305848=diff
==
--- 
libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/prev.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/iterators/iterator.primitives/iterator.operations/prev.pass.cpp
 Tue Jun 20 16:00:02 2017
@@ -71,5 +71,5 @@ int main()
 static_assert( constexpr_test(s+1, s), "" );
 }
 #endif
-
+
 }

Modified: 
libcxx/trunk/test/std/numerics/numeric.ops/exclusive.scan/exclusive_scan.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/numerics/numeric.ops/exclusive.scan/exclusive_scan.pass.cpp?rev=305848=305847=305848=diff
==
--- 
libcxx/trunk/test/std/numerics/numeric.ops/exclusive.scan/exclusive_scan.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/numerics/numeric.ops/exclusive.scan/exclusive_scan.pass.cpp
 Tue Jun 20 16:00:02 2017
@@ -13,7 +13,7 @@
 // template
 // OutputIterator exclusive_scan(InputIterator first, InputIterator last,
 //   

[PATCH] D34417: Switch TestVisitor to Lang_C via -x c

2017-06-20 Thread Stephan Bergmann via Phabricator via cfe-commits
sberg created this revision.

...instead of -std=c99, as the latter lead to

  error: invalid argument '-std=c99' not allowed with 'C++'

complaints in test logs


https://reviews.llvm.org/D34417

Files:
  unittests/Tooling/TestVisitor.h


Index: unittests/Tooling/TestVisitor.h
===
--- unittests/Tooling/TestVisitor.h
+++ unittests/Tooling/TestVisitor.h
@@ -53,7 +53,10 @@
   bool runOver(StringRef Code, Language L = Lang_CXX) {
 std::vector Args;
 switch (L) {
-  case Lang_C: Args.push_back("-std=c99"); break;
+  case Lang_C:
+Args.push_back("-x");
+Args.push_back("c");
+break;
   case Lang_CXX98: Args.push_back("-std=c++98"); break;
   case Lang_CXX11: Args.push_back("-std=c++11"); break;
   case Lang_CXX14: Args.push_back("-std=c++14"); break;


Index: unittests/Tooling/TestVisitor.h
===
--- unittests/Tooling/TestVisitor.h
+++ unittests/Tooling/TestVisitor.h
@@ -53,7 +53,10 @@
   bool runOver(StringRef Code, Language L = Lang_CXX) {
 std::vector Args;
 switch (L) {
-  case Lang_C: Args.push_back("-std=c99"); break;
+  case Lang_C:
+Args.push_back("-x");
+Args.push_back("c");
+break;
   case Lang_CXX98: Args.push_back("-std=c++98"); break;
   case Lang_CXX11: Args.push_back("-std=c++11"); break;
   case Lang_CXX14: Args.push_back("-std=c++14"); break;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r305845 - [clang] Fix format specifiers fixits for nested macros

2017-06-20 Thread Alexander Shaposhnikov via cfe-commits
Author: alexshap
Date: Tue Jun 20 15:46:58 2017
New Revision: 305845

URL: http://llvm.org/viewvc/llvm-project?rev=305845=rev
Log:
[clang] Fix format specifiers fixits for nested macros

ExpansionLoc was previously calculated incorrectly in the case of 
nested macros expansions. In this diff we build the stack of expansions 
where the last one is the actual expansion which should be used 
for grouping together the edits. 
The definition of MacroArgUse is adjusted accordingly.

Test plan: make check-all

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

Modified:
cfe/trunk/include/clang/Edit/EditedSource.h
cfe/trunk/lib/Edit/EditedSource.cpp
cfe/trunk/test/FixIt/fixit-format-darwin.m

Modified: cfe/trunk/include/clang/Edit/EditedSource.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Edit/EditedSource.h?rev=305845=305844=305845=diff
==
--- cfe/trunk/include/clang/Edit/EditedSource.h (original)
+++ cfe/trunk/include/clang/Edit/EditedSource.h Tue Jun 20 15:46:58 2017
@@ -17,6 +17,7 @@
 #include "llvm/ADT/TinyPtrVector.h"
 #include "llvm/Support/Allocator.h"
 #include 
+#include 
 
 namespace clang {
   class LangOptions;
@@ -41,10 +42,20 @@ class EditedSource {
   typedef std::map FileEditsTy;
   FileEditsTy FileEdits;
 
-  // Location of argument use inside the macro body 
-  typedef std::pair MacroArgUse;
-  llvm::DenseMap>
-ExpansionToArgMap;
+  struct MacroArgUse {
+IdentifierInfo *Identifier;
+SourceLocation ImmediateExpansionLoc;
+// Location of argument use inside the top-level macro
+SourceLocation UseLoc;
+
+bool operator==(const MacroArgUse ) const {
+  return std::tie(Identifier, ImmediateExpansionLoc, UseLoc) ==
+ std::tie(Other.Identifier, Other.ImmediateExpansionLoc,
+  Other.UseLoc);
+}
+  };
+
+  llvm::DenseMap> ExpansionToArgMap;
   SmallVector, 2>
 CurrCommitMacroArgExps;
 

Modified: cfe/trunk/lib/Edit/EditedSource.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Edit/EditedSource.cpp?rev=305845=305844=305845=diff
==
--- cfe/trunk/lib/Edit/EditedSource.cpp (original)
+++ cfe/trunk/lib/Edit/EditedSource.cpp Tue Jun 20 15:46:58 2017
@@ -28,13 +28,18 @@ void EditedSource::deconstructMacroArgLo
   MacroArgUse ) {
   assert(SourceMgr.isMacroArgExpansion(Loc));
   SourceLocation DefArgLoc = SourceMgr.getImmediateExpansionRange(Loc).first;
-  ExpansionLoc = SourceMgr.getImmediateExpansionRange(DefArgLoc).first;
+  SourceLocation ImmediateExpansionLoc =
+  SourceMgr.getImmediateExpansionRange(DefArgLoc).first;
+  ExpansionLoc = ImmediateExpansionLoc;
+  while (SourceMgr.isMacroBodyExpansion(ExpansionLoc))
+ExpansionLoc = SourceMgr.getImmediateExpansionRange(ExpansionLoc).first;
   SmallString<20> Buf;
   StringRef ArgName = Lexer::getSpelling(SourceMgr.getSpellingLoc(DefArgLoc),
  Buf, SourceMgr, LangOpts);
-  ArgUse = {nullptr, SourceLocation()};
+  ArgUse = MacroArgUse{nullptr, SourceLocation(), SourceLocation()};
   if (!ArgName.empty())
-ArgUse = {(ArgName), SourceMgr.getSpellingLoc(DefArgLoc)};
+ArgUse = {(ArgName), ImmediateExpansionLoc,
+  SourceMgr.getSpellingLoc(DefArgLoc)};
 }
 
 void EditedSource::startingCommit() {}
@@ -69,10 +74,11 @@ bool EditedSource::canInsertInOffset(Sou
 deconstructMacroArgLoc(OrigLoc, ExpLoc, ArgUse);
 auto I = ExpansionToArgMap.find(ExpLoc.getRawEncoding());
 if (I != ExpansionToArgMap.end() &&
-std::find_if(
-I->second.begin(), I->second.end(), [&](const MacroArgUse ) {
-  return ArgUse.first == U.first && ArgUse.second != U.second;
-}) != I->second.end()) {
+find_if(I->second, [&](const MacroArgUse ) {
+  return ArgUse.Identifier == U.Identifier &&
+ std::tie(ArgUse.ImmediateExpansionLoc, ArgUse.UseLoc) !=
+ std::tie(U.ImmediateExpansionLoc, U.UseLoc);
+}) != I->second.end()) {
   // Trying to write in a macro argument input that has already been
   // written by a previous commit for another expansion of the same macro
   // argument name. For example:
@@ -89,7 +95,6 @@ bool EditedSource::canInsertInOffset(Sou
   return false;
 }
   }
-
   return true;
 }
 
@@ -102,13 +107,13 @@ bool EditedSource::commitInsert(SourceLo
 return true;
 
   if (SourceMgr.isMacroArgExpansion(OrigLoc)) {
-SourceLocation ExpLoc;
 MacroArgUse ArgUse;
+SourceLocation ExpLoc;
 deconstructMacroArgLoc(OrigLoc, ExpLoc, ArgUse);
-if (ArgUse.first)
+if (ArgUse.Identifier)
   

[PATCH] D34268: [clang] Fix format specifiers fixits for nested macros

2017-06-20 Thread Alexander Shaposhnikov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL305845: [clang] Fix format specifiers fixits for nested 
macros (authored by alexshap).

Changed prior to commit:
  https://reviews.llvm.org/D34268?vs=103093=103262#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34268

Files:
  cfe/trunk/include/clang/Edit/EditedSource.h
  cfe/trunk/lib/Edit/EditedSource.cpp
  cfe/trunk/test/FixIt/fixit-format-darwin.m

Index: cfe/trunk/include/clang/Edit/EditedSource.h
===
--- cfe/trunk/include/clang/Edit/EditedSource.h
+++ cfe/trunk/include/clang/Edit/EditedSource.h
@@ -17,6 +17,7 @@
 #include "llvm/ADT/TinyPtrVector.h"
 #include "llvm/Support/Allocator.h"
 #include 
+#include 
 
 namespace clang {
   class LangOptions;
@@ -41,10 +42,20 @@
   typedef std::map FileEditsTy;
   FileEditsTy FileEdits;
 
-  // Location of argument use inside the macro body 
-  typedef std::pair MacroArgUse;
-  llvm::DenseMap>
-ExpansionToArgMap;
+  struct MacroArgUse {
+IdentifierInfo *Identifier;
+SourceLocation ImmediateExpansionLoc;
+// Location of argument use inside the top-level macro
+SourceLocation UseLoc;
+
+bool operator==(const MacroArgUse ) const {
+  return std::tie(Identifier, ImmediateExpansionLoc, UseLoc) ==
+ std::tie(Other.Identifier, Other.ImmediateExpansionLoc,
+  Other.UseLoc);
+}
+  };
+
+  llvm::DenseMap> ExpansionToArgMap;
   SmallVector, 2>
 CurrCommitMacroArgExps;
 
Index: cfe/trunk/test/FixIt/fixit-format-darwin.m
===
--- cfe/trunk/test/FixIt/fixit-format-darwin.m
+++ cfe/trunk/test/FixIt/fixit-format-darwin.m
@@ -57,3 +57,20 @@
   Log3("test 7: %s", getNSInteger(), getNSUInteger());
   // CHECK: Log3("test 7: %ld", (long)getNSInteger(), (unsigned long)getNSUInteger());
 }
+
+#define Outer1(...) \
+do { \
+  printf(__VA_ARGS__); \
+} while (0)
+
+#define Outer2(...) \
+do { \
+  Outer1(__VA_ARGS__); Outer1(__VA_ARGS__); \
+} while (0)
+
+void bug33447() {
+  Outer2("test 8: %s", getNSInteger());  
+  // CHECK: Outer2("test 8: %ld", (long)getNSInteger());
+  Outer2("test 9: %s %s", getNSInteger(), getNSInteger());
+  // CHECK: Outer2("test 9: %ld %ld", (long)getNSInteger(), (long)getNSInteger());
+}
Index: cfe/trunk/lib/Edit/EditedSource.cpp
===
--- cfe/trunk/lib/Edit/EditedSource.cpp
+++ cfe/trunk/lib/Edit/EditedSource.cpp
@@ -28,13 +28,18 @@
   MacroArgUse ) {
   assert(SourceMgr.isMacroArgExpansion(Loc));
   SourceLocation DefArgLoc = SourceMgr.getImmediateExpansionRange(Loc).first;
-  ExpansionLoc = SourceMgr.getImmediateExpansionRange(DefArgLoc).first;
+  SourceLocation ImmediateExpansionLoc =
+  SourceMgr.getImmediateExpansionRange(DefArgLoc).first;
+  ExpansionLoc = ImmediateExpansionLoc;
+  while (SourceMgr.isMacroBodyExpansion(ExpansionLoc))
+ExpansionLoc = SourceMgr.getImmediateExpansionRange(ExpansionLoc).first;
   SmallString<20> Buf;
   StringRef ArgName = Lexer::getSpelling(SourceMgr.getSpellingLoc(DefArgLoc),
  Buf, SourceMgr, LangOpts);
-  ArgUse = {nullptr, SourceLocation()};
+  ArgUse = MacroArgUse{nullptr, SourceLocation(), SourceLocation()};
   if (!ArgName.empty())
-ArgUse = {(ArgName), SourceMgr.getSpellingLoc(DefArgLoc)};
+ArgUse = {(ArgName), ImmediateExpansionLoc,
+  SourceMgr.getSpellingLoc(DefArgLoc)};
 }
 
 void EditedSource::startingCommit() {}
@@ -69,10 +74,11 @@
 deconstructMacroArgLoc(OrigLoc, ExpLoc, ArgUse);
 auto I = ExpansionToArgMap.find(ExpLoc.getRawEncoding());
 if (I != ExpansionToArgMap.end() &&
-std::find_if(
-I->second.begin(), I->second.end(), [&](const MacroArgUse ) {
-  return ArgUse.first == U.first && ArgUse.second != U.second;
-}) != I->second.end()) {
+find_if(I->second, [&](const MacroArgUse ) {
+  return ArgUse.Identifier == U.Identifier &&
+ std::tie(ArgUse.ImmediateExpansionLoc, ArgUse.UseLoc) !=
+ std::tie(U.ImmediateExpansionLoc, U.UseLoc);
+}) != I->second.end()) {
   // Trying to write in a macro argument input that has already been
   // written by a previous commit for another expansion of the same macro
   // argument name. For example:
@@ -89,7 +95,6 @@
   return false;
 }
   }
-
   return true;
 }
 
@@ -102,13 +107,13 @@
 return true;
 
   if (SourceMgr.isMacroArgExpansion(OrigLoc)) {
-SourceLocation ExpLoc;
 MacroArgUse ArgUse;
+SourceLocation ExpLoc;
 deconstructMacroArgLoc(OrigLoc, ExpLoc, ArgUse);
-if (ArgUse.first)
+ 

[PATCH] D34377: Support MS builtins using 'long' on Darwin/LP64

2017-06-20 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno added inline comments.



Comment at: include/clang/Basic/Builtins.def:55
 //  W   -> int64_t
+//  l   -> 'int' if builtin is a MS extensions and the target is Darwin/LP64.
+// Defaults to 'L' otherwise.

rnk wrote:
> majnemer wrote:
> > Why not just LP64? Seems arbitrary to make this Darwin sensitive.
> Every existing prefix is upper case. Do you think it makes it more readable 
> to follow the pattern? Maybe it isn't worth it.
At first attempt I tried to make it more generic, but there seems to be 
different expected behavior in other platforms: for instance, there are 
Linux/LP64 tests that expect 'long' here to be 64-bits, see 
CodeGen/ms-intrinsics-rotations.c.



Comment at: include/clang/Basic/Builtins.def:55
 //  W   -> int64_t
+//  l   -> 'int' if builtin is a MS extensions and the target is Darwin/LP64.
+// Defaults to 'L' otherwise.

bruno wrote:
> rnk wrote:
> > majnemer wrote:
> > > Why not just LP64? Seems arbitrary to make this Darwin sensitive.
> > Every existing prefix is upper case. Do you think it makes it more readable 
> > to follow the pattern? Maybe it isn't worth it.
> At first attempt I tried to make it more generic, but there seems to be 
> different expected behavior in other platforms: for instance, there are 
> Linux/LP64 tests that expect 'long' here to be 64-bits, see 
> CodeGen/ms-intrinsics-rotations.c.
It might be better indeed, but seems like all "good letters" are taken, what 
about 'N'? As for "Narrow" long (Duncan's suggestion)?



Comment at: lib/AST/ASTContext.cpp:8551
+  break;
+}
 case 'W':

rnk wrote:
> compnerd wrote:
> > I agree with @majnemer.  Why not base this on the Int64Type?
> I'd suggest this code:
>   IsSpecialLong = true;
>   // Use "long" if is 32 bits. This prefix is used by intrinsics that need 
> 32-bit types on LP64 platforms, but need to use "long" in the prototype on 
> LLP64 platforms like Win64.
>   if (Context.getTargetInfo().getLongWidth() == 32)
> HowLong = 1;
>   break;
See below.



Comment at: lib/AST/ASTContext.cpp:8551
+  break;
+}
 case 'W':

bruno wrote:
> rnk wrote:
> > compnerd wrote:
> > > I agree with @majnemer.  Why not base this on the Int64Type?
> > I'd suggest this code:
> >   IsSpecialLong = true;
> >   // Use "long" if is 32 bits. This prefix is used by intrinsics that need 
> > 32-bit types on LP64 platforms, but need to use "long" in the prototype on 
> > LLP64 platforms like Win64.
> >   if (Context.getTargetInfo().getLongWidth() == 32)
> > HowLong = 1;
> >   break;
> See below.
I tried something similar before, but I get two tests failing 
CodeGen/ms-intrinsics-rotations.c and CodeGen/pr27892.c. Your suggestion hits 
the same failing tests. Both fails because of the Linux issue mentioned above: 
i32 codegen where i64 is expected. Of course I could improve the condition to 
handle Linux, but at that point I just thing it's better to use Darwin, which 
is what the fix is towards anyway. Additional ideas?


https://reviews.llvm.org/D34377



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


[libcxx] r305843 - [libcxx] [test] Add more tests to tuple_size_structured_bindings.pass.cpp and make it friendlier to C1XX.

2017-06-20 Thread Stephan T. Lavavej via cfe-commits
Author: stl_msft
Date: Tue Jun 20 15:34:50 2017
New Revision: 305843

URL: http://llvm.org/viewvc/llvm-project?rev=305843=rev
Log:
[libcxx] [test] Add more tests to tuple_size_structured_bindings.pass.cpp and 
make it friendlier to C1XX.

Style/paranoia: 42.1 doesn't have an exact binary representation. Although this 
doesn't
cause failures, it makes me uncomfortable, so I'm changing it to 42.5.

C1XX rightly warns about unreferenced variables. Adding tests for their values
makes C1XX happy and improves test coverage.

C1XX (somewhat obnoxiously) warns about seeing a struct specialized as a class.
Although the Standard doesn't care, saying struct consistently is better.
(The Standard itself is still inconsistent about whether to depict tuple_element
and tuple_size as structs or classes.)

Fixes D33953.

Modified:

libcxx/trunk/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_structured_bindings.pass.cpp

Modified: 
libcxx/trunk/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_structured_bindings.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_structured_bindings.pass.cpp?rev=305843=305842=305843=diff
==
--- 
libcxx/trunk/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_structured_bindings.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_size_structured_bindings.pass.cpp
 Tue Jun 20 15:34:50 2017
@@ -64,18 +64,22 @@ void test_decomp_tuple() {
 void test_decomp_pair() {
   typedef std::pair T;
   {
-T s{99, 42.1};
+T s{99, 42.5};
 auto [m1, m2] = s;
 auto& [r1, r2] = s;
 assert(m1 == 99);
+assert(m2 == 42.5);
 assert( == ::get<0>(s));
+assert( == ::get<1>(s));
   }
   {
-T const s{99, 42.1};
+T const s{99, 42.5};
 auto [m1, m2] = s;
 auto& [r1, r2] = s;
 assert(m1 == 99);
+assert(m2 == 42.5);
 assert( == ::get<0>(s));
+assert( == ::get<1>(s));
   }
 }
 
@@ -86,14 +90,22 @@ void test_decomp_array() {
 auto [m1, m2, m3] = s;
 auto& [r1, r2, r3] = s;
 assert(m1 == 99);
+assert(m2 == 42);
+assert(m3 == -1);
 assert( == ::get<0>(s));
+assert( == ::get<1>(s));
+assert( == ::get<2>(s));
   }
   {
 T const s{{99, 42, -1}};
 auto [m1, m2, m3] = s;
 auto& [r1, r2, r3] = s;
 assert(m1 == 99);
+assert(m2 == 42);
+assert(m3 == -1);
 assert( == ::get<0>(s));
+assert( == ::get<1>(s));
+assert( == ::get<2>(s));
   }
 }
 
@@ -105,8 +117,7 @@ template 
 int get(Test const&) { static_assert(N == 0, ""); return -1; }
 
 template <>
-class std::tuple_element<0, Test> {
-public:
+struct std::tuple_element<0, Test> {
   typedef int type;
 };
 
@@ -117,8 +128,7 @@ void test_before_tuple_size_specializati
 }
 
 template <>
-class std::tuple_size {
-public:
+struct std::tuple_size {
   static const size_t value = 1;
 };
 


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


[libcxx] r305841 - Fix discovery of cxxabi.h in the monorepo layout

2017-06-20 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Tue Jun 20 15:34:13 2017
New Revision: 305841

URL: http://llvm.org/viewvc/llvm-project?rev=305841=rev
Log:
Fix discovery of cxxabi.h in the monorepo layout

Modified:
libcxx/trunk/CMakeLists.txt

Modified: libcxx/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/CMakeLists.txt?rev=305841=305840=305841=diff
==
--- libcxx/trunk/CMakeLists.txt (original)
+++ libcxx/trunk/CMakeLists.txt Tue Jun 20 15:34:13 2017
@@ -118,6 +118,7 @@ if (LIBCXX_CXX_ABI STREQUAL "default")
 cxxabi.h
 PATHS ${LLVM_MAIN_SRC_DIR}/projects/libcxxabi/include
   ${LLVM_MAIN_SRC_DIR}/runtimes/libcxxabi/include
+  ${LLVM_MAIN_SRC_DIR}/../libcxxabi/include
 NO_DEFAULT_PATH
   )
   if (LIBCXX_TARGETING_MSVC)


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


[PATCH] D34266: Static Analyzer - Localizability Checker: New Localizable APIs for macOS High Sierra & iOS 11

2017-06-20 Thread Anna Zaks via Phabricator via cfe-commits
zaks.anna added a comment.

> Hmm, should there be new tests that demonstrate that we cover the new APIs?

Unless we use a new registration mechanism for some of these APIs, I'd be fine 
without adding a test for every API that has localization constraints.


Repository:
  rL LLVM

https://reviews.llvm.org/D34266



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


[PATCH] D34294: Rework libcxx strerror_r handling.

2017-06-20 Thread James Y Knight via Phabricator via cfe-commits
jyknight added a comment.

EricWF, wdyt?


https://reviews.llvm.org/D34294



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


[PATCH] D34210: Add __has_feature(leak_sanitizer)

2017-06-20 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

If LSan is a runtime thing, why not use weak hooks or something to detect LSan 
at runtime instead of using a macro?


https://reviews.llvm.org/D34210



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


[libunwind] r305836 - Creating release candidate final from release_401 branch

2017-06-20 Thread Tom Stellard via cfe-commits
Author: tstellar
Date: Tue Jun 20 14:30:24 2017
New Revision: 305836

URL: http://llvm.org/viewvc/llvm-project?rev=305836=rev
Log:
Creating release candidate final from release_401 branch

Added:
libunwind/tags/RELEASE_401/final/   (props changed)
  - copied from r305835, libunwind/branches/release_40/

Propchange: libunwind/tags/RELEASE_401/final/
--
svn:mergeinfo = /libunwind/trunk:292723,296358-296359


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


[libcxxabi] r305830 - Creating release candidate final from release_401 branch

2017-06-20 Thread Tom Stellard via cfe-commits
Author: tstellar
Date: Tue Jun 20 14:29:53 2017
New Revision: 305830

URL: http://llvm.org/viewvc/llvm-project?rev=305830=rev
Log:
Creating release candidate final from release_401 branch

Added:
libcxxabi/tags/RELEASE_401/final/   (props changed)
  - copied from r305829, libcxxabi/branches/release_40/

Propchange: libcxxabi/tags/RELEASE_401/final/
--
svn:mergeinfo = /libcxxabi/trunk:292135,292418,292638


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


[libcxx] r305829 - Creating release candidate final from release_401 branch

2017-06-20 Thread Tom Stellard via cfe-commits
Author: tstellar
Date: Tue Jun 20 14:29:48 2017
New Revision: 305829

URL: http://llvm.org/viewvc/llvm-project?rev=305829=rev
Log:
Creating release candidate final from release_401 branch

Added:
libcxx/tags/RELEASE_401/final/   (props changed)
  - copied from r305828, libcxx/branches/release_40/

Propchange: libcxx/tags/RELEASE_401/final/
--
--- svn:mergeinfo (added)
+++ svn:mergeinfo Tue Jun 20 14:29:48 2017
@@ -0,0 +1,2 @@
+/libcxx/branches/apple:136569-137939
+/libcxx/trunk:292013,292091,292607,292990,293154,293197,293581,294133,294142,294431


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


[PATCH] D34210: Add __has_feature(leak_sanitizer)

2017-06-20 Thread Francis Ricci via Phabricator via cfe-commits
fjricci reclaimed this revision.
fjricci added a comment.

As I've looked into this further, I do think we need 
`has_feature(leak_sanitizer)` after all. For example, if a user program calls 
`pthread_create()` with a custom stack size, leak sanitizer will intercept the 
call to `pthread_create()`, and may modify the stack size set by the user 
(lsan's interceptor for `pthread_create` calls `AdjustStackSize` in 
sanitizer_common). Without `has_feature(leak_sanitizer)`, there's no good way 
for the user program to account for these sorts of modifications. There are 
most likely other interceptors which will cause similar issues, this is just 
the first example I ran into.


https://reviews.llvm.org/D34210



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


[PATCH] D33953: [libcxx] [test] Add more tests to tuple_size_structured_bindings.pass.cpp and make it friendlier to C1XX.

2017-06-20 Thread Stephan T. Lavavej via Phabricator via cfe-commits
STL_MSFT added a comment.

Ping?


https://reviews.llvm.org/D33953



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


[PATCH] D34367: CodeGen: Fix address space of indirect function argument

2017-06-20 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/CodeGen/CGCall.cpp:1605
+  ? CGM.getDataLayout().getAllocaAddrSpace()
+  : getContext().getTargetAddressSpace(LangAS::Default));
   break;

yaxunl wrote:
> rjmccall wrote:
> > Everything about your reasoning seems to apply to normal indirect 
> > arguments, too.
> non-byval indirect argument is normally in default address space instead of 
> alloca address space. For example,
> 
> 
> ```
> struct A { int a;};
> void f(A );
> ```
> `x` is an indirect argument but should not be in alloca addr space, since the 
> caller may pass a reference to a global variable.
'x' is not an indirect argument in this context.  It is a direct argument that 
happens to be of reference type.

A normal Indirect argument is when the ABI says an argument should implicitly 
be passed as a pointer to a temporary.  IndirectByVal is when the ABI says that 
something should be passed directly in the arguments area of the stack.  Some 
targets never use indirect arguments for normal C cases, but they're still used 
for direct non-POD arguments in C++.


https://reviews.llvm.org/D34367



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


[PATCH] D33842: [AMDGPU] Fix address space of global variable

2017-06-20 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked 3 inline comments as done.
yaxunl added inline comments.



Comment at: include/clang/Basic/TargetInfo.h:959
+  /// \brief Return the target address space which is read only and can be
+  /// casted to the generic address space.
+  virtual llvm::Optional getTargetConstantAddressSpace() const {

rjmccall wrote:
> "Return an AST address space which can be used opportunistically for constant 
> global memory.  It must be possible to convert pointers into this address 
> space to LangAS::Default.  If no such address space exists, this may return 
> None, and such optimizations will be disabled."
I will change it. Also I think getConstantAddressSpace may be a better name 
since we will return AST addr space.



Comment at: lib/CodeGen/CGExpr.cpp:449
+ Var, ConvertTypeForMem(E->getType())->getPointerTo()),
  Object.getAlignment());
 // If the temporary is a global and has a constant initializer or is a

rjmccall wrote:
> Every time you're tempted to use getPointerCast, you should instead be using 
> the target hook to lift the pointer into the right address space.
I am going to fix it. However this seems not the right place to do the addr 
space cast. I am going to do it in createReferenceTemporary instead.


https://reviews.llvm.org/D33842



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


[PATCH] D28953: [analyzer] Eliminate analyzer limitations on symbolic constraint generation

2017-06-20 Thread Dominic Chen via Phabricator via cfe-commits
ddcc added a comment.

I forgot to mention that the only remaining test failure is on 
`plist-macros.cpp`; there is a `Assuming condition is true` path note that only 
appears with the RangeConstraintManager but not with Z3ConstraintManager, and I 
can't `#ifdef` it because the annotations are checked by `FileCheck`.


https://reviews.llvm.org/D28953



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


[PATCH] D28953: [analyzer] Eliminate analyzer limitations on symbolic constraint generation

2017-06-20 Thread Dominic Chen via Phabricator via cfe-commits
ddcc updated this revision to Diff 103239.
ddcc added a comment.

Rebase, decrease simplification complexity


https://reviews.llvm.org/D28953

Files:
  include/clang/StaticAnalyzer/Checkers/SValExplainer.h
  lib/StaticAnalyzer/Core/SValBuilder.cpp
  lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
  lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp
  test/Analysis/bitwise-ops.c
  test/Analysis/bool-assignment.c
  test/Analysis/conditional-path-notes.c
  test/Analysis/explain-svals.cpp
  test/Analysis/plist-macros.cpp
  test/Analysis/range_casts.c
  test/Analysis/std-c-library-functions.c

Index: test/Analysis/std-c-library-functions.c
===
--- test/Analysis/std-c-library-functions.c
+++ test/Analysis/std-c-library-functions.c
@@ -57,8 +57,7 @@
   size_t y = fread(buf, sizeof(int), 10, fp);
   clang_analyzer_eval(y <= 10); // expected-warning{{TRUE}}
   size_t z = fwrite(buf, sizeof(int), y, fp);
-  // FIXME: should be TRUE once symbol-symbol constraint support is improved.
-  clang_analyzer_eval(z <= y); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(z <= y); // expected-warning{{TRUE}}
 }
 
 ssize_t getline(char **, size_t *, FILE *);
Index: test/Analysis/range_casts.c
===
--- test/Analysis/range_casts.c
+++ test/Analysis/range_casts.c
@@ -67,8 +67,8 @@
 {
   unsigned index = -1;
   if (index < foo) index = foo;
-  if (index - 1 == 0) // Was not reached prior fix.
-clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  if (index - 1 == 0)
+clang_analyzer_warnIfReached(); // no-warning
   else
 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
 }
@@ -87,8 +87,8 @@
 {
   unsigned index = -1;
   if (index < foo) index = foo;
-  if (index - 1L == 0L) // Was not reached prior fix.
-clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  if (index - 1L == 0L)
+clang_analyzer_warnIfReached(); // no-warning
   else
 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
 }
@@ -117,8 +117,8 @@
 {
   unsigned index = -1;
   if (index < foo) index = foo;
-  if (index - 1UL == 0L) // Was not reached prior fix.
-clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  if (index - 1UL == 0L)
+clang_analyzer_warnIfReached(); // no-warning
   else
 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
 }
Index: test/Analysis/plist-macros.cpp
===
--- test/Analysis/plist-macros.cpp
+++ test/Analysis/plist-macros.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=core,unix -analyzer-eagerly-assume -verify %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix -analyzer-eagerly-assume -analyzer-output=plist-multi-file -analyzer-config path-diagnostics-alternate=ture %s -o %t.plist
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix -analyzer-eagerly-assume -analyzer-output=plist-multi-file -analyzer-config path-diagnostics-alternate=true %s -o %t.plist
 // RUN: FileCheck --input-file=%t.plist %s
 
 
@@ -85,6 +85,7 @@
 void test2(int *p) {
   CALL_FN(p);
 }
+
 // CHECK:  diagnostics
 // CHECK-NEXT:  
 // CHECK-NEXT:   
@@ -636,6 +637,69 @@
 // CHECK-NEXT: end
 // CHECK-NEXT:  
 // CHECK-NEXT:   
+// CHECK-NEXT:line36
+// CHECK-NEXT:col7
+// CHECK-NEXT:file0
+// CHECK-NEXT:   
+// CHECK-NEXT:   
+// CHECK-NEXT:line36
+// CHECK-NEXT:col7
+// CHECK-NEXT:file0
+// CHECK-NEXT:   
+// CHECK-NEXT:  
+// CHECK-NEXT:
+// CHECK-NEXT:   
+// CHECK-NEXT: 
+// CHECK-NEXT: 
+// CHECK-NEXT:  kindevent
+// CHECK-NEXT:  location
+// CHECK-NEXT:  
+// CHECK-NEXT:   line36
+// CHECK-NEXT:   col7
+// CHECK-NEXT:   file0
+// CHECK-NEXT:  
+// CHECK-NEXT:  ranges
+// CHECK-NEXT:  
+// CHECK-NEXT:
+// CHECK-NEXT: 
+// CHECK-NEXT:  line36
+// CHECK-NEXT:  col7
+// CHECK-NEXT:  file0
+// CHECK-NEXT: 
+// CHECK-NEXT: 
+// CHECK-NEXT:  line36
+// CHECK-NEXT:  col25
+// CHECK-NEXT:  file0
+// CHECK-NEXT: 
+// CHECK-NEXT:
+// CHECK-NEXT:  
+// CHECK-NEXT:  depth0
+// CHECK-NEXT:  extended_message
+// CHECK-NEXT:  Assuming the condition is true
+// CHECK-NEXT:  message
+// CHECK-NEXT:  Assuming the condition is true
+// CHECK-NEXT: 
+// CHECK-NEXT: 
+// CHECK-NEXT:  kindcontrol
+// CHECK-NEXT:  edges
+// CHECK-NEXT:   
+// CHECK-NEXT:
+// CHECK-NEXT: start
+// CHECK-NEXT:  
+// CHECK-NEXT:   
+// CHECK-NEXT:line36
+// CHECK-NEXT:col7
+// CHECK-NEXT:file0
+// CHECK-NEXT:   
+// CHECK-NEXT:   
+// CHECK-NEXT:line36
+// 

[PATCH] D28953: [analyzer] Eliminate analyzer limitations on symbolic constraint generation

2017-06-20 Thread Dominic Chen via Phabricator via cfe-commits
ddcc added a comment.

> Can we drop computing these for some expressions that we know the 
> RangeConstraintManager will not utilize?

It's possible, though I'm not sure what the actual limitations of the 
RangeConstraintManager are, since there are a lot of intermediate steps that 
attempt to transform unsupported expressions into supported ones.

> We could implement the TODO described below and possibly also lower the 
> MaxComp value. This means that instead of keeping a complex expression and 
> constraints on every symbol used in that expression, we would conjure a new 
> symbol and associate a new constrain derived from the expression with it. 
> (Would this strategy also work for the Z3 case?)

I think it's feasible, but would probably require some more to code to handle 
`SymbolConjured` (right now all `SymbolData` are treated as variables).

> Would it help to decrease 100 to 10 here?

Yes, changing it to 10 eliminates the excessive recursion; combined runtime 
drops to 282 sec on the testcases (~8 sec for Range only, ~271 sec for Z3 only; 
doesn't sum due to separate executions). This appears to be the most 
straightforward solution.

> (2) With RangeConstraintManager, simplification is not entirely idempotent: 
> we may simplify a symbol further when one of its sub-symbols gets constrained 
> to a constant in a new state. However, apart from that, we might be able to 
> avoid re-simplifying the same symbol by caching results based on the (symbol, 
> state's constraint data) pair. Probably it may work with Z3 as well.

Yeah, that would also fix this issue. In general, I think there's plenty of 
room for improvements from caching, especially for queries to e.g. 
`getSymVal()`.


https://reviews.llvm.org/D28953



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


[PATCH] D34370: Fix for Bug 33471: Preventing operator auto from resolving to a template operator.

2017-06-20 Thread Erich Keane via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL305812: Fix for Bug 33471: Preventing operator auto from 
resolving to a templateā€¦ (authored by erichkeane).

Changed prior to commit:
  https://reviews.llvm.org/D34370?vs=103224=103235#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34370

Files:
  cfe/trunk/lib/Sema/SemaLookup.cpp
  cfe/trunk/test/SemaCXX/cxx1y-deduced-return-type.cpp


Index: cfe/trunk/test/SemaCXX/cxx1y-deduced-return-type.cpp
===
--- cfe/trunk/test/SemaCXX/cxx1y-deduced-return-type.cpp
+++ cfe/trunk/test/SemaCXX/cxx1y-deduced-return-type.cpp
@@ -55,6 +55,25 @@
   return "goodbye";
 }
 
+// Allow 'operator auto' to call only the explicit operator auto.
+struct BothOps {
+  template  operator T();
+  template  operator T *();
+  operator auto() { return 0; }
+  operator auto *() { return this; }
+};
+struct JustTemplateOp {
+  template  operator T();
+  template  operator T *();
+};
+
+auto c() {
+  BothOps().operator auto(); // ok
+  BothOps().operator auto *(); // ok
+  JustTemplateOp().operator auto(); // expected-error {{no member named 
'operator auto' in 'JustTemplateOp'}}
+  JustTemplateOp().operator auto *(); // expected-error {{no member named 
'operator auto *' in 'JustTemplateOp'}}
+}
+
 auto *ptr_1() {
   return 100; // expected-error {{cannot deduce return type 'auto *' from 
returned value of type 'int'}}
 }
Index: cfe/trunk/lib/Sema/SemaLookup.cpp
===
--- cfe/trunk/lib/Sema/SemaLookup.cpp
+++ cfe/trunk/lib/Sema/SemaLookup.cpp
@@ -862,6 +862,16 @@
   if (!Record->isCompleteDefinition())
 return Found;
 
+  // For conversion operators, 'operator auto' should only match
+  // 'operator auto'.  Since 'auto' is not a type, it shouldn't be considered
+  // as a candidate for template substitution.
+  auto *ContainedDeducedType =
+  R.getLookupName().getCXXNameType()->getContainedDeducedType();
+  if (R.getLookupName().getNameKind() ==
+  DeclarationName::CXXConversionFunctionName &&
+  ContainedDeducedType && ContainedDeducedType->isUndeducedType())
+return Found;
+
   for (CXXRecordDecl::conversion_iterator U = Record->conversion_begin(),
  UEnd = Record->conversion_end(); U != UEnd; ++U) {
 FunctionTemplateDecl *ConvTemplate = dyn_cast(*U);


Index: cfe/trunk/test/SemaCXX/cxx1y-deduced-return-type.cpp
===
--- cfe/trunk/test/SemaCXX/cxx1y-deduced-return-type.cpp
+++ cfe/trunk/test/SemaCXX/cxx1y-deduced-return-type.cpp
@@ -55,6 +55,25 @@
   return "goodbye";
 }
 
+// Allow 'operator auto' to call only the explicit operator auto.
+struct BothOps {
+  template  operator T();
+  template  operator T *();
+  operator auto() { return 0; }
+  operator auto *() { return this; }
+};
+struct JustTemplateOp {
+  template  operator T();
+  template  operator T *();
+};
+
+auto c() {
+  BothOps().operator auto(); // ok
+  BothOps().operator auto *(); // ok
+  JustTemplateOp().operator auto(); // expected-error {{no member named 'operator auto' in 'JustTemplateOp'}}
+  JustTemplateOp().operator auto *(); // expected-error {{no member named 'operator auto *' in 'JustTemplateOp'}}
+}
+
 auto *ptr_1() {
   return 100; // expected-error {{cannot deduce return type 'auto *' from returned value of type 'int'}}
 }
Index: cfe/trunk/lib/Sema/SemaLookup.cpp
===
--- cfe/trunk/lib/Sema/SemaLookup.cpp
+++ cfe/trunk/lib/Sema/SemaLookup.cpp
@@ -862,6 +862,16 @@
   if (!Record->isCompleteDefinition())
 return Found;
 
+  // For conversion operators, 'operator auto' should only match
+  // 'operator auto'.  Since 'auto' is not a type, it shouldn't be considered
+  // as a candidate for template substitution.
+  auto *ContainedDeducedType =
+  R.getLookupName().getCXXNameType()->getContainedDeducedType();
+  if (R.getLookupName().getNameKind() ==
+  DeclarationName::CXXConversionFunctionName &&
+  ContainedDeducedType && ContainedDeducedType->isUndeducedType())
+return Found;
+
   for (CXXRecordDecl::conversion_iterator U = Record->conversion_begin(),
  UEnd = Record->conversion_end(); U != UEnd; ++U) {
 FunctionTemplateDecl *ConvTemplate = dyn_cast(*U);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r305812 - Fix for Bug 33471: Preventing operator auto from resolving to a template operator.

2017-06-20 Thread Erich Keane via cfe-commits
Author: erichkeane
Date: Tue Jun 20 12:38:07 2017
New Revision: 305812

URL: http://llvm.org/viewvc/llvm-project?rev=305812=rev
Log:
Fix for Bug 33471: Preventing operator auto from resolving to a template 
operator.

As the bug report says,
struct A
{

  template operator T();

};

void foo()
{

  A().operator auto();

}

causes: "undeduced type in IR-generation
UNREACHABLE executed at llvm/tools/clang/lib/CodeGen/CodeGenFunction.cpp:208!"

The problem is that in this case, "T" is being deduced as "auto", 
which I believe is incorrect.

The 'operator auto' implementation in Clang is standards compliant, however 
there is a defect report against core (1670).

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

Modified:
cfe/trunk/lib/Sema/SemaLookup.cpp
cfe/trunk/test/SemaCXX/cxx1y-deduced-return-type.cpp

Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=305812=305811=305812=diff
==
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Tue Jun 20 12:38:07 2017
@@ -862,6 +862,16 @@ static bool LookupDirect(Sema , Lookup
   if (!Record->isCompleteDefinition())
 return Found;
 
+  // For conversion operators, 'operator auto' should only match
+  // 'operator auto'.  Since 'auto' is not a type, it shouldn't be considered
+  // as a candidate for template substitution.
+  auto *ContainedDeducedType =
+  R.getLookupName().getCXXNameType()->getContainedDeducedType();
+  if (R.getLookupName().getNameKind() ==
+  DeclarationName::CXXConversionFunctionName &&
+  ContainedDeducedType && ContainedDeducedType->isUndeducedType())
+return Found;
+
   for (CXXRecordDecl::conversion_iterator U = Record->conversion_begin(),
  UEnd = Record->conversion_end(); U != UEnd; ++U) {
 FunctionTemplateDecl *ConvTemplate = dyn_cast(*U);

Modified: cfe/trunk/test/SemaCXX/cxx1y-deduced-return-type.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx1y-deduced-return-type.cpp?rev=305812=305811=305812=diff
==
--- cfe/trunk/test/SemaCXX/cxx1y-deduced-return-type.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx1y-deduced-return-type.cpp Tue Jun 20 12:38:07 
2017
@@ -55,6 +55,25 @@ auto b(bool k) {
   return "goodbye";
 }
 
+// Allow 'operator auto' to call only the explicit operator auto.
+struct BothOps {
+  template  operator T();
+  template  operator T *();
+  operator auto() { return 0; }
+  operator auto *() { return this; }
+};
+struct JustTemplateOp {
+  template  operator T();
+  template  operator T *();
+};
+
+auto c() {
+  BothOps().operator auto(); // ok
+  BothOps().operator auto *(); // ok
+  JustTemplateOp().operator auto(); // expected-error {{no member named 
'operator auto' in 'JustTemplateOp'}}
+  JustTemplateOp().operator auto *(); // expected-error {{no member named 
'operator auto *' in 'JustTemplateOp'}}
+}
+
 auto *ptr_1() {
   return 100; // expected-error {{cannot deduce return type 'auto *' from 
returned value of type 'int'}}
 }


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


[PATCH] D34367: CodeGen: Fix address space of indirect function argument

2017-06-20 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: lib/CodeGen/CGCall.cpp:1605
+  ? CGM.getDataLayout().getAllocaAddrSpace()
+  : getContext().getTargetAddressSpace(LangAS::Default));
   break;

rjmccall wrote:
> Everything about your reasoning seems to apply to normal indirect arguments, 
> too.
non-byval indirect argument is normally in default address space instead of 
alloca address space. For example,


```
struct A { int a;};
void f(A );
```
`x` is an indirect argument but should not be in alloca addr space, since the 
caller may pass a reference to a global variable.


https://reviews.llvm.org/D34367



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


[PATCH] D34377: Support MS builtins using 'long' on Darwin/LP64

2017-06-20 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added inline comments.



Comment at: include/clang/Basic/Builtins.def:55
 //  W   -> int64_t
+//  l   -> 'int' if builtin is a MS extensions and the target is Darwin/LP64.
+// Defaults to 'L' otherwise.

majnemer wrote:
> Why not just LP64? Seems arbitrary to make this Darwin sensitive.
Every existing prefix is upper case. Do you think it makes it more readable to 
follow the pattern? Maybe it isn't worth it.



Comment at: lib/AST/ASTContext.cpp:8551
+  break;
+}
 case 'W':

compnerd wrote:
> I agree with @majnemer.  Why not base this on the Int64Type?
I'd suggest this code:
  IsSpecialLong = true;
  // Use "long" if is 32 bits. This prefix is used by intrinsics that need 
32-bit types on LP64 platforms, but need to use "long" in the prototype on 
LLP64 platforms like Win64.
  if (Context.getTargetInfo().getLongWidth() == 32)
HowLong = 1;
  break;


https://reviews.llvm.org/D34377



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


[PATCH] D28691: Add OpenCL 2.0 atomic builtin functions as Clang builtin

2017-06-20 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: include/clang/Basic/Builtins.def:713
+ATOMIC_BUILTIN(__opencl_atomic_fetch_or, "v.", "t")
+ATOMIC_BUILTIN(__opencl_atomic_fetch_xor, "v.", "t")
+

What about min/max? I believe they will need to have the scope too. 



Comment at: include/clang/Basic/DiagnosticSemaKinds.td:6956
+  "synchronization scope argument to atomic operation is invalid">;
+def err_atomic_op_has_non_constant_synch_scope : Error<
+  "non-constant synchronization scope argument to atomic operation is not 
supported">;

Btw, is this disallowed by the spec? Can't find anything relevant.



Comment at: lib/CodeGen/CGAtomic.cpp:678
 RValue CodeGenFunction::EmitAtomicExpr(AtomicExpr *E) {
+  bool IsOpenCL = E->isOpenCL();
   QualType AtomicTy = E->getPtr()->getType()->getPointeeType();

Seems short enough to introduce an extra variable here. :)



Comment at: lib/CodeGen/CGAtomic.cpp:707
 
-  switch (E->getOp()) {
+  auto Op = E->getOp();
+  switch (Op) {

The same here... not sure adding an extra variable is helping here. :)



Comment at: lib/CodeGen/CGAtomic.cpp:889
+return V;
+  auto OrigLangAS = E->getType()
+.getTypePtr()

Formatting seems to be a bit odd here...



Comment at: lib/CodeGen/CGAtomic.cpp:1117
+  "Non-constant synchronization scope not supported");
+  auto sco = (llvm::SynchronizationScope)(
+  cast(Scope)->getZExtValue());

Variable name doesn't follow the style.



Comment at: lib/CodeGen/CGAtomic.cpp:1117
+  "Non-constant synchronization scope not supported");
+  auto sco = (llvm::SynchronizationScope)(
+  cast(Scope)->getZExtValue());

Anastasia wrote:
> Variable name doesn't follow the style.
could we avoid using C style cast?



Comment at: lib/Sema/SemaChecking.cpp:3146
+Op == AtomicExpr::AO__opencl_atomic_load)
+? 0
+: 1);

formatting seems odd.



Comment at: test/CodeGenOpenCL/atomic-ops-libcall.cl:1
+// RUN: %clang_cc1 < %s -cl-std=CL2.0 -finclude-default-header -triple spir64 
-emit-llvm | FileCheck -check-prefix=GEN4 %s
+// RUN: %clang_cc1 < %s -cl-std=CL2.0 -finclude-default-header -triple 
armv5e-none-linux-gnueabi -emit-llvm | FileCheck -check-prefix=GEN0 %s

GEN4 -> SPIR



Comment at: test/CodeGenOpenCL/atomic-ops-libcall.cl:2
+// RUN: %clang_cc1 < %s -cl-std=CL2.0 -finclude-default-header -triple spir64 
-emit-llvm | FileCheck -check-prefix=GEN4 %s
+// RUN: %clang_cc1 < %s -cl-std=CL2.0 -finclude-default-header -triple 
armv5e-none-linux-gnueabi -emit-llvm | FileCheck -check-prefix=GEN0 %s
+

GEN0 -> AMDGPU



Comment at: test/CodeGenOpenCL/atomic-ops-libcall.cl:4
+
+void f(atomic_int *i, int cmp) {
+  int x;

Could we use different scopes?



Comment at: test/CodeGenOpenCL/atomic-ops.cl:7
+
+#ifndef ALREADY_INCLUDED
+#define ALREADY_INCLUDED

why do we need this?



Comment at: test/CodeGenOpenCL/atomic-ops.cl:15
+  // CHECK: load atomic i32, i32 addrspace(4)* %{{[.0-9A-Z_a-z]+}} 
singlethread seq_cst
+  int x = __opencl_atomic_load(i, memory_order_seq_cst, 
memory_scope_work_item);
+}

I think we could use different scope types all over...



Comment at: test/CodeGenOpenCL/atomic-ops.cl:32
+  // CHECK-LABEL: @fi4(
+  // CHECK: [[PAIR:%[.0-9A-Z_a-z]+]] = cmpxchg i32 addrspace(4)* 
[[PTR:%[.0-9A-Z_a-z]+]], i32 [[EXPECTED:%[.0-9A-Z_a-z]+]], i32 
[[DESIRED:%[.0-9A-Z_a-z]+]] singlethread acquire acquire
+  // CHECK: [[OLD:%[.0-9A-Z_a-z]+]] = extractvalue { i32, i1 } [[PAIR]], 0

do we have an addrspacecast before?



Comment at: test/SemaOpenCL/atomic-ops.cl:22
+   intptr_t *P, float *D, struct S *s1, struct S *s2) {
+  __opencl_atomic_init(I, 5); // expected-error {{pointer to _Atomic}}
+  __opencl_atomic_init(ci, 5); // expected-error {{address argument to atomic 
operation must be a pointer to non-const _Atomic type ('const __generic 
atomic_int *' (aka 'const __generic _Atomic(int) *') invalid)}}

could we have the full error for consistency?



Comment at: test/SemaOpenCL/atomic-ops.cl:30
+  __opencl_atomic_store(i, 0, memory_order_relaxed, memory_scope_work_item);
+  __opencl_atomic_store(ci, 0, memory_order_relaxed, memory_scope_work_item); 
// expected-error {{address argument to atomic operation must be a pointer to 
non-const _Atomic type ('const __generic atomic_int *' (aka 'const __generic 
_Atomic(int) *') invalid)}}
+

could we also test with constant AS? Also I would generally improve testing wrt 
address spaces...



[PATCH] D33383: [GSoC] Flag value completion for clang

2017-06-20 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi closed this revision.
yamaguchi added a comment.

Landed in https://reviews.llvm.org/rL305805.


https://reviews.llvm.org/D33383



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


[PATCH] D34370: Fix for Bug 33471: Preventing operator auto from resolving to a template operator.

2017-06-20 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: lib/Sema/SemaLookup.cpp:870
+  DeclarationName::CXXConversionFunctionName &&
+  R.getLookupName().getCXXNameType()->getContainedDeducedType() &&
+  R.getLookupName()

rsmith wrote:
> Maybe only call this once?
Sure, I'll extract this into a variable above the if statement before 
committing.


https://reviews.llvm.org/D34370



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


r305805 - [GSoC] Flag value completion for clang

2017-06-20 Thread Yuka Takahashi via cfe-commits
Author: yamaguchi
Date: Tue Jun 20 11:31:31 2017
New Revision: 305805

URL: http://llvm.org/viewvc/llvm-project?rev=305805=rev
Log:
[GSoC] Flag value completion for clang

This is patch for GSoC project, bash-completion for clang.

To use this on bash, please run `source clang/utils/bash-autocomplete.sh`.
bash-autocomplete.sh is code for bash-completion.

In this patch, Options.td was mainly changed in order to add value class
in Options.inc.

Modified:
cfe/trunk/include/clang/Driver/Options.h
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/lib/Driver/Driver.cpp
cfe/trunk/lib/Driver/DriverOptions.cpp
cfe/trunk/test/Driver/autocomplete.c
cfe/trunk/utils/bash-autocomplete.sh

Modified: cfe/trunk/include/clang/Driver/Options.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.h?rev=305805=305804=305805=diff
==
--- cfe/trunk/include/clang/Driver/Options.h (original)
+++ cfe/trunk/include/clang/Driver/Options.h Tue Jun 20 11:31:31 2017
@@ -39,8 +39,9 @@ enum ClangFlags {
 
 enum ID {
 OPT_INVALID = 0, // This is not an option ID.
-#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
-   HELPTEXT, METAVAR) OPT_##ID,
+#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  
\
+   HELPTEXT, METAVAR, VALUES)  
\
+  OPT_##ID,
 #include "clang/Driver/Options.inc"
 LastOption
 #undef OPTION

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=305805=305804=305805=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Tue Jun 20 11:31:31 2017
@@ -493,7 +493,7 @@ def cl_mad_enable : Flag<["-"], "cl-mad-
 def cl_no_signed_zeros : Flag<["-"], "cl-no-signed-zeros">, 
Group, Flags<[CC1Option]>,
   HelpText<"OpenCL only. Allow use of less precise no signed zeros 
computations in the generated binary.">;
 def cl_std_EQ : Joined<["-"], "cl-std=">, Group, 
Flags<[CC1Option]>,
-  HelpText<"OpenCL language standard to compile for.">;
+  HelpText<"OpenCL language standard to compile for.">, 
Values<"cl,CL,cl1.1,CL1.1,cl1.2,CL1.2,cl2.0,CL2.0">;
 def cl_denorms_are_zero : Flag<["-"], "cl-denorms-are-zero">, 
Group, Flags<[CC1Option]>,
   HelpText<"OpenCL only. Allow denormals to be flushed to zero.">;
 def cl_fp32_correctly_rounded_divide_sqrt : Flag<["-"], 
"cl-fp32-correctly-rounded-divide-sqrt">, Group, 
Flags<[CC1Option]>,
@@ -804,7 +804,7 @@ def fno_sanitize_coverage
 : CommaJoined<["-"], "fno-sanitize-coverage=">,
   Group, Flags<[CoreOption, DriverOption]>,
   HelpText<"Disable specified features of coverage instrumentation for "
-   "Sanitizers">;
+   "Sanitizers">, 
Values<"func,bb,edge,indirect-calls,trace-bb,trace-cmp,trace-div,trace-gep,8bit-counters,trace-pc,trace-pc-guard,no-prune,inline-8bit-counters">;
 def fsanitize_memory_track_origins_EQ : Joined<["-"], 
"fsanitize-memory-track-origins=">,
 Group,
 HelpText<"Enable origins tracking in 
MemorySanitizer">;
@@ -923,7 +923,7 @@ def ftrapping_math : Flag<["-"], "ftrapp
 def fno_trapping_math : Flag<["-"], "fno-trapping-math">, Group, 
Flags<[CC1Option]>;
 def ffp_contract : Joined<["-"], "ffp-contract=">, Group,
   Flags<[CC1Option]>, HelpText<"Form fused FP ops (e.g. FMAs): fast 
(everywhere)"
-  " | on (according to FP_CONTRACT pragma, default) | off (never fuse)">;
+  " | on (according to FP_CONTRACT pragma, default) | off (never fuse)">, 
Values<"fast,on,off">;
 
 def ffor_scope : Flag<["-"], "ffor-scope">, Group;
 def fno_for_scope : Flag<["-"], "fno-for-scope">, Group;
@@ -1000,7 +1000,7 @@ def flat__namespace : Flag<["-"], "flat_
 def flax_vector_conversions : Flag<["-"], "flax-vector-conversions">, 
Group;
 def flimited_precision_EQ : Joined<["-"], "flimited-precision=">, 
Group;
 def flto_EQ : Joined<["-"], "flto=">, Flags<[CoreOption, CC1Option]>, 
Group,
-  HelpText<"Set LTO mode to either 'full' or 'thin'">;
+  HelpText<"Set LTO mode to either 'full' or 'thin'">, Values<"thin,full">;
 def flto : Flag<["-"], "flto">, Flags<[CoreOption, CC1Option]>, Group,
   HelpText<"Enable LTO in 'full' mode">;
 def fno_lto : Flag<["-"], "fno-lto">, Group,
@@ -1158,7 +1158,7 @@ def fno_experimental_new_pass_manager :
   Group, Flags<[CC1Option]>,
   HelpText<"Disables an experimental new pass manager in LLVM.">;
 def fveclib : Joined<["-"], "fveclib=">, Group, Flags<[CC1Option]>,
-HelpText<"Use the given vector functions library">;
+HelpText<"Use the given vector functions library">, 
Values<"Accelerate,SVML,none">;
 def fno_lax_vector_conversions : Flag<["-"], 

[PATCH] D34370: Fix for Bug 33471: Preventing operator auto from resolving to a template operator.

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

Looks good, thanks!




Comment at: lib/Sema/SemaLookup.cpp:870
+  DeclarationName::CXXConversionFunctionName &&
+  R.getLookupName().getCXXNameType()->getContainedDeducedType() &&
+  R.getLookupName()

Maybe only call this once?


https://reviews.llvm.org/D34370



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


[PATCH] D34370: Fix for Bug 33471: Preventing operator auto from resolving to a template operator.

2017-06-20 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 103224.
erichkeane marked an inline comment as done.
erichkeane added a comment.

Hi @rsmith 
Thanks for the quick response!  I spent a while going over it, and think I have 
what you were looking for.  I Also added the operator auto * tests.


https://reviews.llvm.org/D34370

Files:
  lib/Sema/SemaLookup.cpp
  test/SemaCXX/cxx1y-deduced-return-type.cpp


Index: test/SemaCXX/cxx1y-deduced-return-type.cpp
===
--- test/SemaCXX/cxx1y-deduced-return-type.cpp
+++ test/SemaCXX/cxx1y-deduced-return-type.cpp
@@ -55,6 +55,25 @@
   return "goodbye";
 }
 
+// Allow 'operator auto' to call only the explicit operator auto.
+struct BothOps {
+  template  operator T();
+  template  operator T *();
+  operator auto() { return 0; }
+  operator auto *() { return this; }
+};
+struct JustTemplateOp {
+  template  operator T();
+  template  operator T *();
+};
+
+auto c() {
+  BothOps().operator auto(); // ok
+  BothOps().operator auto *(); // ok
+  JustTemplateOp().operator auto(); // expected-error {{no member named 
'operator auto' in 'JustTemplateOp'}}
+  JustTemplateOp().operator auto *(); // expected-error {{no member named 
'operator auto *' in 'JustTemplateOp'}}
+}
+
 auto *ptr_1() {
   return 100; // expected-error {{cannot deduce return type 'auto *' from 
returned value of type 'int'}}
 }
Index: lib/Sema/SemaLookup.cpp
===
--- lib/Sema/SemaLookup.cpp
+++ lib/Sema/SemaLookup.cpp
@@ -862,6 +862,19 @@
   if (!Record->isCompleteDefinition())
 return Found;
 
+  // For conversion operators, 'operator auto' should only match
+  // 'operator auto'.  Since 'auto' is not a type, it shouldn't be considered
+  // as a candidate for template substitution.
+  if (R.getLookupName().getNameKind() ==
+  DeclarationName::CXXConversionFunctionName &&
+  R.getLookupName().getCXXNameType()->getContainedDeducedType() &&
+  R.getLookupName()
+  .getCXXNameType()
+  ->getContainedDeducedType()
+  ->isUndeducedType()) {
+return Found;
+  }
+
   for (CXXRecordDecl::conversion_iterator U = Record->conversion_begin(),
  UEnd = Record->conversion_end(); U != UEnd; ++U) {
 FunctionTemplateDecl *ConvTemplate = dyn_cast(*U);


Index: test/SemaCXX/cxx1y-deduced-return-type.cpp
===
--- test/SemaCXX/cxx1y-deduced-return-type.cpp
+++ test/SemaCXX/cxx1y-deduced-return-type.cpp
@@ -55,6 +55,25 @@
   return "goodbye";
 }
 
+// Allow 'operator auto' to call only the explicit operator auto.
+struct BothOps {
+  template  operator T();
+  template  operator T *();
+  operator auto() { return 0; }
+  operator auto *() { return this; }
+};
+struct JustTemplateOp {
+  template  operator T();
+  template  operator T *();
+};
+
+auto c() {
+  BothOps().operator auto(); // ok
+  BothOps().operator auto *(); // ok
+  JustTemplateOp().operator auto(); // expected-error {{no member named 'operator auto' in 'JustTemplateOp'}}
+  JustTemplateOp().operator auto *(); // expected-error {{no member named 'operator auto *' in 'JustTemplateOp'}}
+}
+
 auto *ptr_1() {
   return 100; // expected-error {{cannot deduce return type 'auto *' from returned value of type 'int'}}
 }
Index: lib/Sema/SemaLookup.cpp
===
--- lib/Sema/SemaLookup.cpp
+++ lib/Sema/SemaLookup.cpp
@@ -862,6 +862,19 @@
   if (!Record->isCompleteDefinition())
 return Found;
 
+  // For conversion operators, 'operator auto' should only match
+  // 'operator auto'.  Since 'auto' is not a type, it shouldn't be considered
+  // as a candidate for template substitution.
+  if (R.getLookupName().getNameKind() ==
+  DeclarationName::CXXConversionFunctionName &&
+  R.getLookupName().getCXXNameType()->getContainedDeducedType() &&
+  R.getLookupName()
+  .getCXXNameType()
+  ->getContainedDeducedType()
+  ->isUndeducedType()) {
+return Found;
+  }
+
   for (CXXRecordDecl::conversion_iterator U = Record->conversion_begin(),
  UEnd = Record->conversion_end(); U != UEnd; ++U) {
 FunctionTemplateDecl *ConvTemplate = dyn_cast(*U);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D33842: [AMDGPU] Fix address space of global variable

2017-06-20 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: include/clang/Basic/TargetInfo.h:959
+  /// \brief Return the target address space which is read only and can be
+  /// casted to the generic address space.
+  virtual llvm::Optional getTargetConstantAddressSpace() const {

"Return an AST address space which can be used opportunistically for constant 
global memory.  It must be possible to convert pointers into this address space 
to LangAS::Default.  If no such address space exists, this may return None, and 
such optimizations will be disabled."



Comment at: lib/CodeGen/CGExpr.cpp:357
+unsigned AddrSpace =
+CGF.getTarget().getTargetConstantAddressSpace().getValueOr(0);
 auto *GV = new llvm::GlobalVariable(

This isn't the right logic.  Part of what I was saying before is that this 
optimization isn't obviously supportable on all targets.  You should call 
getTargetConstantAddressSpace() and then only try to do this optimization if it 
doesn't return None.

For parity, the default implementation should return 0.



Comment at: lib/CodeGen/CGExpr.cpp:449
+ Var, ConvertTypeForMem(E->getType())->getPointerTo()),
  Object.getAlignment());
 // If the temporary is a global and has a constant initializer or is a

Every time you're tempted to use getPointerCast, you should instead be using 
the target hook to lift the pointer into the right address space.


https://reviews.llvm.org/D33842



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


[PATCH] D34277: [analyzer] Bump default performance thresholds?

2017-06-20 Thread Anna Zaks via Phabricator via cfe-commits
zaks.anna added a comment.

> In particular, there are patches to generate more symbolic expressions, that 
> could also degrade the performance (but fix some fixmes along the way).

The patch you are talking about might be promising, but needs much more 
investigation and tuning for performance vs issues found. I do not think we 
should block this patch until the investigation is done.


https://reviews.llvm.org/D34277



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


r305804 - Add a missing '[' to the tests from r305719

2017-06-20 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Tue Jun 20 11:16:11 2017
New Revision: 305804

URL: http://llvm.org/viewvc/llvm-project?rev=305804=rev
Log:
Add a missing '[' to the tests from r305719

This clarifies the tests as the missing ']' is important, and not the '['.

Modified:
cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m
cfe/trunk/test/Parser/objc-at-interface-eof-crash.m

Modified: cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m?rev=305804=305803=305804=diff
==
--- cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m (original)
+++ cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m Tue Jun 20 
11:16:11 2017
@@ -13,7 +13,7 @@
 @implementation ClassB // expected-note {{implementation started here}}
 
 - (void) method:(ClassA *)mgr { // expected-note {{to match this '{'}}
-  mgr fileExistsAtPath:0
+  [mgr fileExistsAtPath:0
 } // expected-error {{expected ']'}}
 
 @implementation ClassC //  \

Modified: cfe/trunk/test/Parser/objc-at-interface-eof-crash.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/objc-at-interface-eof-crash.m?rev=305804=305803=305804=diff
==
--- cfe/trunk/test/Parser/objc-at-interface-eof-crash.m (original)
+++ cfe/trunk/test/Parser/objc-at-interface-eof-crash.m Tue Jun 20 11:16:11 2017
@@ -13,7 +13,7 @@
 @implementation ClassB // expected-note {{implementation started here}}
 
 - (void) method:(ClassA *)mgr { // expected-note {{to match this '{'}}
-  mgr fileExistsAtPath:0
+  [mgr fileExistsAtPath:0
 } // expected-error {{expected ']'}}
 
 @interface ClassC //   \


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


Re: r305719 - [Parser][ObjC] Use an artificial EOF token while parsing lexed ObjC methods

2017-06-20 Thread Alex L via cfe-commits
On 20 June 2017 at 16:53, Duncan P. N. Exon Smith 
wrote:

>
> On Jun 19, 2017, at 10:53, Alex Lorenz via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
> Author: arphaman
> Date: Mon Jun 19 12:53:21 2017
> New Revision: 305719
>
> URL: http://llvm.org/viewvc/llvm-project?rev=305719=rev
> Log:
> [Parser][ObjC] Use an artificial EOF token while parsing lexed ObjC methods
>
> This change avoid a crash that occurred when skipping to EOF while parsing
> an
> ObjC interface/implementation.
>
> rdar://31963299
>
> Differential Revision: https://reviews.llvm.org/D34185
>
> Added:
>cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m
>cfe/trunk/test/Parser/objc-at-interface-eof-crash.m
> Modified:
>cfe/trunk/lib/Parse/ParseObjc.cpp
>
> Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/
> ParseObjc.cpp?rev=305719=305718=305719=diff
> 
> ==
> --- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
> +++ cfe/trunk/lib/Parse/ParseObjc.cpp Mon Jun 19 12:53:21 2017
> @@ -3627,6 +3627,14 @@ void Parser::ParseLexedObjCMethodDefs(Le
>   SourceLocation OrigLoc = Tok.getLocation();
>
>   assert(!LM.Toks.empty() && "ParseLexedObjCMethodDef - Empty body!");
> +  // Store an artificial EOF token to ensure that we don't run off the
> end of
> +  // the method's body when we come to parse it.
> +  Token Eof;
> +  Eof.startToken();
> +  Eof.setKind(tok::eof);
> +  Eof.setEofData(MCDecl);
> +  Eof.setLocation(OrigLoc);
> +  LM.Toks.push_back(Eof);
>   // Append the current token at the end of the new token stream so that it
>   // doesn't get lost.
>   LM.Toks.push_back(Tok);
> @@ -3658,7 +3666,7 @@ void Parser::ParseLexedObjCMethodDefs(Le
>   Actions.ActOnDefaultCtorInitializers(MCDecl);
> ParseFunctionStatementBody(MCDecl, BodyScope);
>   }
> -
> +
>   if (Tok.getLocation() != OrigLoc) {
> // Due to parsing error, we either went over the cached tokens or
> // there are still cached tokens left. If it's the latter case skip the
> @@ -3670,4 +3678,6 @@ void Parser::ParseLexedObjCMethodDefs(Le
>   while (Tok.getLocation() != OrigLoc && Tok.isNot(tok::eof))
> ConsumeAnyToken();
>   }
> +  // Clean up the remaining EOF token.
> +  ConsumeAnyToken();
> }
>
> Added: cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/
> objc-at-implementation-eof-crash.m?rev=305719=auto
> 
> ==
> --- cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m (added)
> +++ cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m Mon Jun 19
> 12:53:21 2017
> @@ -0,0 +1,21 @@
> +// RUN: %clang_cc1 -verify -Wno-objc-root-class %s
> +
> +@interface ClassA
> +
> +- (void)fileExistsAtPath:(int)x;
> +
> +@end
> +
> +@interface ClassB
> +
> +@end
> +
> +@implementation ClassB // expected-note {{implementation started here}}
> +
> +- (void) method:(ClassA *)mgr { // expected-note {{to match this '{'}}
> +  mgr fileExistsAtPath:0
> +} // expected-error {{expected ']'}}
> +
> +@implementation ClassC // expected-error {{missing '@end'}} //
> expected-error {{expected '}'}} // expected-warning {{cannot find interface
> declaration for 'ClassC'}}
>
>
> I believe you can split these expectations over multiple lines.  Something
> like this seems more readable:
>
> @implementation ClassC \
>   // expected-error {{missing '@end'}} \
>   // expected-error {{expected '}'}}   \
>   // expected-warning {{cannot find interface declaration for 'ClassC'}}
>
>
Thanks, addressed in r305803!


>
> +
> +@end
>
> Added: cfe/trunk/test/Parser/objc-at-interface-eof-crash.m
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/
> objc-at-interface-eof-crash.m?rev=305719=auto
> 
> ==
> --- cfe/trunk/test/Parser/objc-at-interface-eof-crash.m (added)
> +++ cfe/trunk/test/Parser/objc-at-interface-eof-crash.m Mon Jun 19
> 12:53:21 2017
> @@ -0,0 +1,21 @@
> +// RUN: %clang_cc1 -verify -Wno-objc-root-class %s
> +
> +@interface ClassA
> +
> +- (void)fileExistsAtPath:(int)x;
> +
> +@end
> +
> +@interface ClassB
> +
> +@end
> +
> +@implementation ClassB // expected-note {{implementation started here}}
> +
> +- (void) method:(ClassA *)mgr { // expected-note {{to match this '{'}}
> +  mgr fileExistsAtPath:0
> +} // expected-error {{expected ']'}}
> +
> +@interface ClassC // expected-error {{missing '@end'}} // expected-error
> {{expected '}'}}
>
>
> Same recommendation as above.
>
> +
> +@end
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
>
>
___
cfe-commits mailing list

r305803 - Split the expectations in tests from r305719 over multiple lines to

2017-06-20 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Tue Jun 20 11:12:26 2017
New Revision: 305803

URL: http://llvm.org/viewvc/llvm-project?rev=305803=rev
Log:
Split the expectations in tests from r305719 over multiple lines to
enhance readability

As suggested by Duncan Exon Smith!

Modified:
cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m
cfe/trunk/test/Parser/objc-at-interface-eof-crash.m

Modified: cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m?rev=305803=305802=305803=diff
==
--- cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m (original)
+++ cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m Tue Jun 20 
11:12:26 2017
@@ -16,6 +16,9 @@
   mgr fileExistsAtPath:0
 } // expected-error {{expected ']'}}
 
-@implementation ClassC // expected-error {{missing '@end'}} // expected-error 
{{expected '}'}} // expected-warning {{cannot find interface declaration for 
'ClassC'}}
+@implementation ClassC //  \
+  // expected-error {{missing '@end'}} \
+  // expected-error {{expected '}'}}   \
+  // expected-warning {{cannot find interface declaration for 'ClassC'}}
 
 @end

Modified: cfe/trunk/test/Parser/objc-at-interface-eof-crash.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/objc-at-interface-eof-crash.m?rev=305803=305802=305803=diff
==
--- cfe/trunk/test/Parser/objc-at-interface-eof-crash.m (original)
+++ cfe/trunk/test/Parser/objc-at-interface-eof-crash.m Tue Jun 20 11:12:26 2017
@@ -16,6 +16,8 @@
   mgr fileExistsAtPath:0
 } // expected-error {{expected ']'}}
 
-@interface ClassC // expected-error {{missing '@end'}} // expected-error 
{{expected '}'}}
+@interface ClassC //   \
+  // expected-error {{missing '@end'}} \
+  // expected-error {{expected '}'}}
 
 @end


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


[PATCH] D34287: Moved code hanlding precompiled preamble out of the ASTUnit.

2017-06-20 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: include/clang/Frontend/PrecompiledPreamble.h:124
+/// CanReusePreamble + AddImplicitPreamble to make use of it.
+class PrecompiledPreamble {
+public:

klimek wrote:
> ilya-biryukov wrote:
> > klimek wrote:
> > > If a user doesn't care about the things above this class, can we move 
> > > those into an extra header?
> > Do you have any suggestions of where to put it and how to call it?
> > I didn't think it's a good idea to put something like 'PreambleFileHash.h' 
> > and 'TempPCHFile.h' into 'include/clang/Frontend/'. (Given that they are 
> > essential an implementation detail of PrecompiledPreamble, exposing them in 
> > public include folders seems like a bad idea).
> TempPCHFile looks like something we just want to put into the .cc file and 
> store as a unique_ptr.
> PreambleFileHash seems fine as an extra header.
Made both inner classes of PrecompiledPreamble instead.
The only thing we have outside PrecompiledPreamble now is PreambleBounds. But 
it doesn't look like a big distraction.



Comment at: include/clang/Frontend/PrecompiledPreamble.h:157-160
+  /// We don't expose PCHFile to avoid changing interface when we'll add an
+  /// in-memory PCH, so we declare this function as friend so that it has 
access
+  /// to PCHFile field.
+  friend void AddImplicitPreamble(CompilerInvocation ,

klimek wrote:
> ilya-biryukov wrote:
> > klimek wrote:
> > > Why not make it a member instead?
> > To keep BuildPreamble, CanReusePreamble and AddImplicitPreamble close to 
> > each other.
> > I.e. PrecompiledPreamble only stores data used by these functions.
> > 
> > We could make all of those members, of course. Do you think that would make 
> > API better?
> Generally, if these are closely coupled to implementation details of 
> PrecompiledPreample, I think that coupling is strong enough to warrant making 
> them members.
> On the other hand, making some functions members, and others non-members, and 
> putting them next to each other in the .cc file also would work.
Made all three useful functions members(BuildPreamble is now a static member, 
too, called PrecompiledPreamble::Build).

Also removed some accessors that weren't used outside those functions.
And made a PrecompiledPreamble constructor private, so Build is the only 
function in the interface that creates a preamble. 


https://reviews.llvm.org/D34287



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


[PATCH] D34367: CodeGen: Fix address space of indirect function argument

2017-06-20 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/CodeGen/CGCall.cpp:1605
+  ? CGM.getDataLayout().getAllocaAddrSpace()
+  : getContext().getTargetAddressSpace(LangAS::Default));
   break;

Everything about your reasoning seems to apply to normal indirect arguments, 
too.


https://reviews.llvm.org/D34367



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


[PATCH] D34275: [analyzer] Re-implemente current virtual calls checker in a path-sensitive way

2017-06-20 Thread wangxin via Phabricator via cfe-commits
wangxindsb updated this revision to Diff 103214.
wangxindsb added a comment.

Correct some error in VirtualCallChecker.cpp.
Complete the test case.


https://reviews.llvm.org/D34275

Files:
  lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
  test/Analysis/virtualcall.cpp

Index: test/Analysis/virtualcall.cpp
===
--- test/Analysis/virtualcall.cpp
+++ test/Analysis/virtualcall.cpp
@@ -1,79 +1,49 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -verify -std=c++11 %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -analyzer-config optin.cplusplus.VirtualCall:Interprocedural=true -DINTERPROCEDURAL=1 -verify -std=c++11 %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -analyzer-config optin.cplusplus.VirtualCall:PureOnly=true -DPUREONLY=1 -verify -std=c++11 %s
 
-/* When INTERPROCEDURAL is set, we expect diagnostics in all functions reachable
-   from a constructor or destructor. If it is not set, we expect diagnostics
-   only in the constructor or destructor.
-
-   When PUREONLY is set, we expect diagnostics only for calls to pure virtual
-   functions not to non-pure virtual functions.
-*/
+// RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -analyzer-config optin.cplusplus.VirtualCall:PureOnly=true -DPUREONLY=1 -verify -std=c++11 %s
 
 class A {
 public:
   A();
   A(int i);
 
   ~A() {};
   
-  virtual int foo() = 0; // from Sema: expected-note {{'foo' declared here}}
-  virtual void bar() = 0;
+  virtual int foo(); // from Sema: expected-note {{'foo' declared here}}
+  virtual void bar();
   void f() {
 foo();
-#if INTERPROCEDURAL
-// expected-warning-re@-2 ^}}Call Path : foo <-- fCall to pure virtual function during construction has undefined behavior}}
-#endif
+// expected-warning:Call to virtual function during construction
   }
 };
 
 class B : public A {
 public:
   B() {
 foo();
-#if !PUREONLY
-#if INTERPROCEDURAL
-// expected-warning-re@-3 ^}}Call Path : fooCall to virtual function during construction will not dispatch to derived class}}
-#else
-// expected-warning-re@-5 ^}}Call to virtual function during construction will not dispatch to derived class}}
-#endif
-#endif
-
+// expected-warning:Call to virtual function during construction
   }
   ~B();
   
   virtual int foo();
   virtual void bar() { foo(); }
-#if INTERPROCEDURAL
-  // expected-warning-re@-2 ^}}Call Path : foo <-- barCall to virtual function during destruction will not dispatch to derived class}}
-#endif
+  // expected-warning:Call to virtual function during destruction
 };
 
 A::A() {
   f();
 }
 
 A::A(int i) {
   foo(); // From Sema: expected-warning {{call to pure virtual member function 'foo' has undefined behavior}}
-#if INTERPROCEDURAL
-  // expected-warning-re@-2 ^}}Call Path : fooCall to pure virtual function during construction has undefined behavior}}
-#else
-  // expected-warning-re@-4 ^}}Call to pure virtual function during construction has undefined behavior}}
-#endif
+  // expected-warning:Call to virtual function during construction
 }
 
 B::~B() {
   this->B::foo(); // no-warning
   this->B::bar();
   this->foo();
-#if !PUREONLY
-#if INTERPROCEDURAL
-  // expected-warning-re@-3 ^}}Call Path : fooCall to virtual function during destruction will not dispatch to derived class}}
-#else
-  // expected-warning-re@-5 ^}}Call to virtual function during destruction will not dispatch to derived class}}
-#endif
-#endif
-
+  // expected-warning:Call to virtual function during destruction
 }
 
 class C : public B {
@@ -87,13 +57,7 @@
 
 C::C() {
   f(foo());
-#if !PUREONLY
-#if INTERPROCEDURAL
-  // expected-warning-re@-3 ^}}Call Path : fooCall to virtual function during construction will not dispatch to derived class}}
-#else
-  // expected-warning-re@-5 ^}}Call to virtual function during construction will not dispatch to derived class}}
-#endif
-#endif
+  // expected-warning:Call to virtual function during construction
 }
 
 class D : public B {
@@ -115,7 +79,6 @@
   int foo() override;
 };
 
-// Regression test: don't crash when there's no direct callee.
 class F {
 public:
   F() {
@@ -125,17 +88,68 @@
   void foo();
 };
 
-int main() {
-  A *a;
-  B *b;
-  C *c;
-  D *d;
-  E *e;
-  F *f;
-}
+class G {
+public:
+  virtual void bar();
+  void foo() {
+bar();
+  // no warning
+  }
+};
 
-#include "virtualcall.h"
+class H{
+public:
+  H() : initState(0) { init(); }
+  int initState;
+  virtual void f() const;
+  void init() {
+if (initState)
+  f();
+  // no warning
+  }
 
-#define AS_SYSTEM
-#include "virtualcall.h"
-#undef AS_SYSTEM
+  H(int i) {
+G g;
+g.foo();
+g.bar();
+  // no warning
+f();
+ 

[PATCH] D34287: Moved code hanlding precompiled preamble out of the ASTUnit.

2017-06-20 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 103216.
ilya-biryukov added a comment.

- Made TempPCHFile an inner class of PrecompiledPreamble.
- Made PreambleFileHash an inner class of PrecompiledPreamble.
- Changed stanalone functions to members.
- Removed some member accessors that were no longer used.


https://reviews.llvm.org/D34287

Files:
  include/clang/Frontend/ASTUnit.h
  include/clang/Frontend/PrecompiledPreamble.h
  lib/Frontend/ASTUnit.cpp
  lib/Frontend/CMakeLists.txt
  lib/Frontend/PrecompiledPreamble.cpp

Index: lib/Frontend/PrecompiledPreamble.cpp
===
--- /dev/null
+++ lib/Frontend/PrecompiledPreamble.cpp
@@ -0,0 +1,561 @@
+//===--- PrecompiledPreamble.cpp - Build precompiled preambles --*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Helper class to build precompiled preamble.
+//
+//===--===//
+
+#include "clang/Frontend/PrecompiledPreamble.h"
+#include "clang/AST/DeclObjC.h"
+#include "clang/Basic/TargetInfo.h"
+#include "clang/Basic/VirtualFileSystem.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/CompilerInvocation.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Frontend/FrontendOptions.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Lex/PreprocessorOptions.h"
+#include "clang/Serialization/ASTWriter.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringSet.h"
+#include "llvm/Support/CrashRecoveryContext.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Mutex.h"
+#include "llvm/Support/MutexGuard.h"
+
+using namespace clang;
+
+namespace {
+
+/// Keeps a track of files to be deleted in destructor.
+class TemporaryFiles {
+public:
+  // A static instance to be used by
+  static TemporaryFiles ();
+
+private:
+  // Disallow constructing the class directly.
+  TemporaryFiles() = default;
+  // Disallow copy.
+  TemporaryFiles(const TemporaryFiles &) = delete;
+
+public:
+  ~TemporaryFiles();
+
+  /// Adds \p File to a set of tracked files.
+  void addFile(StringRef File);
+
+  /// Remove \p File from disk and from the set of tracked files.
+  void removeFile(StringRef File);
+
+private:
+  llvm::sys::SmartMutex Mutex;
+  llvm::StringSet<> Files;
+};
+
+TemporaryFiles ::getInstance() {
+  static TemporaryFiles Instance;
+  return Instance;
+}
+
+TemporaryFiles::~TemporaryFiles() {
+  llvm::MutexGuard Guard(Mutex);
+  for (const auto  : Files)
+llvm::sys::fs::remove(File.getKey());
+}
+
+void TemporaryFiles::addFile(StringRef File) {
+  llvm::MutexGuard Guard(Mutex);
+  auto IsInserted = Files.insert(File).second;
+  assert(IsInserted && "File has already been added");
+}
+
+void TemporaryFiles::removeFile(StringRef File) {
+  llvm::MutexGuard Guard(Mutex);
+  auto WasPresent = Files.erase(File);
+  assert(WasPresent && "File was not tracked");
+  llvm::sys::fs::remove(File);
+}
+
+class PreambleMacroCallbacks : public PPCallbacks {
+public:
+  PreambleMacroCallbacks(PreambleCallbacks ) : Callbacks(Callbacks) {}
+
+  void MacroDefined(const Token ,
+const MacroDirective *MD) override {
+Callbacks.HandleMacroDefined(MacroNameTok, MD);
+  }
+
+private:
+  PreambleCallbacks 
+};
+
+class PrecompilePreambleAction : public ASTFrontendAction {
+public:
+  PrecompilePreambleAction(PreambleCallbacks )
+  : Callbacks(Callbacks) {}
+
+  std::unique_ptr CreateASTConsumer(CompilerInstance ,
+ StringRef InFile) override;
+
+  bool hasEmittedPreamblePCH() const { return HasEmittedPreamblePCH; }
+
+  void setEmittedPreamblePCH(ASTWriter ) {
+this->HasEmittedPreamblePCH = true;
+Callbacks.AfterPCHEmitted(Writer);
+  }
+
+  bool shouldEraseOutputFiles() override { return !hasEmittedPreamblePCH(); }
+  bool hasCodeCompletionSupport() const override { return false; }
+  bool hasASTFileSupport() const override { return false; }
+  TranslationUnitKind getTranslationUnitKind() override { return TU_Prefix; }
+
+private:
+  friend class PrecompilePreambleConsumer;
+
+  bool HasEmittedPreamblePCH = false;
+  PreambleCallbacks 
+};
+
+class PrecompilePreambleConsumer : public PCHGenerator {
+public:
+  PrecompilePreambleConsumer(PrecompilePreambleAction ,
+ const Preprocessor , StringRef isysroot,
+ std::unique_ptr Out)
+  : PCHGenerator(PP, "", isysroot, std::make_shared(),
+ ArrayRef(),
+ /*AllowASTWithErrors=*/true),
+Action(Action), Out(std::move(Out)) {}
+
+  bool HandleTopLevelDecl(DeclGroupRef DG) override {
+Action.Callbacks.HandleTopLevelDecl(DG);
+

RE: r284060 - Implement MS _BitScan intrinsics

2017-06-20 Thread Erik Schwiebert via cfe-commits
LGTM, assuming "howLong" == 0 means 32-bit int. ļ˜Š

-Original Message-
From: Bruno Cardoso Lopes [mailto:bruno.card...@gmail.com] 
Sent: Monday, June 19, 2017 6:45 PM
To: Duncan P. N. Exon Smith 
Cc: Reid Kleckner ; Erik Schwiebert ; 
Brian Kelley ; Tomasz Kukielka ; 
cfe-commits 
Subject: Re: r284060 - Implement MS _BitScan intrinsics

On Fri, Jun 16, 2017 at 5:08 PM, Duncan P. N. Exon Smith
 wrote:
>
> On Jun 16, 2017, at 11:02, Reid Kleckner  wrote:
>
> We should fix it.
>
>
> Agreed.
>
> We just need a new character code in the builtin function prototype
> encoding. Currently there is no encoding for a portable int32_t that
> magically becomes "long" on 32-bit Windows. The closest thing we have is
> 'W', which is used by Neon intrinsics to select between "long" and "long
> long". It was added in r202004.
>
>
> Yup, I saw the 'W' as well.  That's the same approach I was using in a patch
> yesterday morning (I picked lowercase L ('l'), but there may be a better
> choice).  Likely Bruno will follow up with a working patch soon (I hit some
> problems with tests and then got tied up).

Right, here it is: 
https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Freviews.llvm.org%2FD34377=02%7C01%7Ceriksc%40microsoft.com%7C622ea4cd65f846cd1be708d4b77dfaa1%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636335199097092827=abfnUWviZ01v%2B%2B43Q6vLvZoBk2QbawkzKNpayIgMJwY%3D=0

Let me know what you guys think!

>
> On Fri, Jun 16, 2017 at 10:28 AM, Erik Schwiebert 
> wrote:
>>
>> We (Office developers for Apple platforms at Microsoft) would prefer to
>> have the intrinsics work properly for LP64, as that will generate the most
>> optimal and efficient code. That said, we understand that this may be odd to
>> implement from the compiler's perspective and can work around it if the
>> intrinsics are not supported for ms-extensions+LP64. At the end of the day
>> we need the compiler to clearly adopt one of those two options, and not sit
>> somewhere in the middle as it currently does. We don't turn on any flags
>> other than -fms-extensions; we donā€™t attempt to define MSC_VER and we do
>> conditionalize code based on __clang__ so the code is aware it is being
>> compiled by clang vs MSVC.
>>
>> So I think we'd prefer what Duncan and Apple are offering to do, but if
>> the larger clang community thinks that is a bad idea and wants to explicitly
>> disable the intrinsics, we could live with that.
>>
>> Thanks,
>> Schwieb
>>
>> -Original Message-
>> From: Erik Schwiebert
>> Sent: Friday, June 16, 2017 8:49 AM
>> To: 'Bruno Cardoso Lopes' ; Brian Kelley
>> ; Tomasz Kukielka 
>> Cc: dexonsm...@apple.com; Reid Kleckner ; cfe-commits
>> 
>> Subject: RE: r284060 - Implement MS _BitScan intrinsics
>>
>> Adding Brian and Tomasz. I'm pretty sure we have the Windows SDK
>> intrinsics headers. I'm not sure which method we'd prefer, so I'll walk down
>> the hall and ask them. Tomasz is our header maestro (because we play crazy
>> #include_next games so we can use both Windows and macOS SDKs!)
>>
>> We'll get back to you ASAP.
>>
>> Schwieb
>>
>> -Original Message-
>> From: Bruno Cardoso Lopes [mailto:bruno.card...@gmail.com]
>> Sent: Thursday, June 15, 2017 4:41 PM
>> To: Erik Schwiebert 
>> Cc: dexonsm...@apple.com; Reid Kleckner ; cfe-commits
>> 
>> Subject: Re: r284060 - Implement MS _BitScan intrinsics
>>
>> On Tue, Jun 13, 2017 at 8:13 PM, Bruno Cardoso Lopes
>>  wrote:
>> > On Mon, Jun 12, 2017 at 2:01 PM, Erik Schwiebert via cfe-commits
>> >  wrote:
>> >> SGTM too. Regarding Duncan's last question -- I can't think of any such
>> >> customer. :) If you all think the right thing for clang to do is to infer
>> >> LLP64 behavior on LP64 (Darwin) + ms_extensions, then that is fine with 
>> >> me!
>>
>> Thinking more about this; what if we mark such builtins as unsupported
>> for "LP64 (Darwin) + ms_extensions" and then you provide the
>> definitions via intrin.h (we can generate a compiler macro for this
>> scenario and conditionalize the include_next as we do for _MSC_VER)?
>> Do you use this header at all? Are there any other MS related flags
>> that get passed to the compiler?
>>
>> > SGTM as well!
>> >
>> >>
>> >> Thanks all!
>> >> Schwieb
>> >>
>> >> -Original Message-
>> >> From: dexonsm...@apple.com [mailto:dexonsm...@apple.com]
>> >> Sent: Monday, June 12, 2017 1:55 PM
>> >> To: Reid Kleckner 
>> >> Cc: Saleem Abdulrasool ; Albert Gutowski
>> >> ; David Majnemer ;
>> >> 

[PATCH] D34198: Fix __has_trivial_destructor crash when the type is incomplete with unknown array bounds.

2017-06-20 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/Sema/SemaExprCXX.cpp:4128
+return true;
+}
+

I don't understand the difference you're creating between traits here.  Three 
specific traits about destructibility allow incomplete array types regardless 
of whether the base type is incomplete, but the rest do not?

Anyway, I think what you want here is basically just:

  if (auto ArrayTy = S.Context.getAsIncompleteArrayType(ArgTy)) {
ArgTy = ArrayTy->getElementType();
  }


https://reviews.llvm.org/D34198



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


[PATCH] D34342: [OpenCL] Fix code generation of function-scope constant samplers.

2017-06-20 Thread Alexey Bader via Phabricator via cfe-commits
bader added a comment.

Wow...
Nice catch.
For some reason I can't reproduce the problem neither.
I will drop source code change, but I'd like to modify the test anyway.
https://reviews.llvm.org/rL277024 added test/CodeGenOpenCL/sampler.cl and 
modified test/SemaOpenCL/sampler_t.cl.
I want to move the parts of the test/SemaOpenCL/sampler_t.cl, which are 
supposed to pass semantic analysis to test/CodeGenOpenCL/sampler.cl and 
validate the LLVM IR after code generation.
Are you OK with this?


https://reviews.llvm.org/D34342



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


[PATCH] D34275: [analyzer] Re-implemente current virtual calls checker in a path-sensitive way

2017-06-20 Thread wangxin via Phabricator via cfe-commits
wangxindsb marked 5 inline comments as done.
wangxindsb added inline comments.



Comment at: VirtualCallChecker.cpp:260
+  if (SFC->inTopFrame()) {
+  const FunctionDecl *FD = SFC->getDecl()->getAsFunction();
+if (!FD)

xazax.hun wrote:
> The formatting seems to be off here I recommend using clang format.
Sorry, can you explain what this means?


https://reviews.llvm.org/D34275



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


Re: r305719 - [Parser][ObjC] Use an artificial EOF token while parsing lexed ObjC methods

2017-06-20 Thread Duncan P. N. Exon Smith via cfe-commits

> On Jun 19, 2017, at 10:53, Alex Lorenz via cfe-commits 
>  wrote:
> 
> Author: arphaman
> Date: Mon Jun 19 12:53:21 2017
> New Revision: 305719
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=305719=rev
> Log:
> [Parser][ObjC] Use an artificial EOF token while parsing lexed ObjC methods
> 
> This change avoid a crash that occurred when skipping to EOF while parsing an
> ObjC interface/implementation.
> 
> rdar://31963299
> 
> Differential Revision: https://reviews.llvm.org/D34185
> 
> Added:
>cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m
>cfe/trunk/test/Parser/objc-at-interface-eof-crash.m
> Modified:
>cfe/trunk/lib/Parse/ParseObjc.cpp
> 
> Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=305719=305718=305719=diff
> ==
> --- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
> +++ cfe/trunk/lib/Parse/ParseObjc.cpp Mon Jun 19 12:53:21 2017
> @@ -3627,6 +3627,14 @@ void Parser::ParseLexedObjCMethodDefs(Le
>   SourceLocation OrigLoc = Tok.getLocation();
> 
>   assert(!LM.Toks.empty() && "ParseLexedObjCMethodDef - Empty body!");
> +  // Store an artificial EOF token to ensure that we don't run off the end of
> +  // the method's body when we come to parse it.
> +  Token Eof;
> +  Eof.startToken();
> +  Eof.setKind(tok::eof);
> +  Eof.setEofData(MCDecl);
> +  Eof.setLocation(OrigLoc);
> +  LM.Toks.push_back(Eof);
>   // Append the current token at the end of the new token stream so that it
>   // doesn't get lost.
>   LM.Toks.push_back(Tok);
> @@ -3658,7 +3666,7 @@ void Parser::ParseLexedObjCMethodDefs(Le
>   Actions.ActOnDefaultCtorInitializers(MCDecl);
> ParseFunctionStatementBody(MCDecl, BodyScope);
>   }
> -  
> +
>   if (Tok.getLocation() != OrigLoc) {
> // Due to parsing error, we either went over the cached tokens or
> // there are still cached tokens left. If it's the latter case skip the
> @@ -3670,4 +3678,6 @@ void Parser::ParseLexedObjCMethodDefs(Le
>   while (Tok.getLocation() != OrigLoc && Tok.isNot(tok::eof))
> ConsumeAnyToken();
>   }
> +  // Clean up the remaining EOF token.
> +  ConsumeAnyToken();
> }
> 
> Added: cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m?rev=305719=auto
> ==
> --- cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m (added)
> +++ cfe/trunk/test/Parser/objc-at-implementation-eof-crash.m Mon Jun 19 
> 12:53:21 2017
> @@ -0,0 +1,21 @@
> +// RUN: %clang_cc1 -verify -Wno-objc-root-class %s
> +
> +@interface ClassA
> +
> +- (void)fileExistsAtPath:(int)x;
> +
> +@end
> +
> +@interface ClassB
> +
> +@end
> +
> +@implementation ClassB // expected-note {{implementation started here}}
> +
> +- (void) method:(ClassA *)mgr { // expected-note {{to match this '{'}}
> +  mgr fileExistsAtPath:0
> +} // expected-error {{expected ']'}}
> +
> +@implementation ClassC // expected-error {{missing '@end'}} // 
> expected-error {{expected '}'}} // expected-warning {{cannot find interface 
> declaration for 'ClassC'}}

I believe you can split these expectations over multiple lines.  Something like 
this seems more readable:

@implementation ClassC \
  // expected-error {{missing '@end'}} \
  // expected-error {{expected '}'}}   \
  // expected-warning {{cannot find interface declaration for 'ClassC'}}

> +
> +@end
> 
> Added: cfe/trunk/test/Parser/objc-at-interface-eof-crash.m
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/objc-at-interface-eof-crash.m?rev=305719=auto
> ==
> --- cfe/trunk/test/Parser/objc-at-interface-eof-crash.m (added)
> +++ cfe/trunk/test/Parser/objc-at-interface-eof-crash.m Mon Jun 19 12:53:21 
> 2017
> @@ -0,0 +1,21 @@
> +// RUN: %clang_cc1 -verify -Wno-objc-root-class %s
> +
> +@interface ClassA
> +
> +- (void)fileExistsAtPath:(int)x;
> +
> +@end
> +
> +@interface ClassB
> +
> +@end
> +
> +@implementation ClassB // expected-note {{implementation started here}}
> +
> +- (void) method:(ClassA *)mgr { // expected-note {{to match this '{'}}
> +  mgr fileExistsAtPath:0
> +} // expected-error {{expected ']'}}
> +
> +@interface ClassC // expected-error {{missing '@end'}} // expected-error 
> {{expected '}'}}

Same recommendation as above.

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

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


[PATCH] D34329: [GSoC] Clang AST diffing

2017-06-20 Thread Johannes Altmanninger via Phabricator via cfe-commits
johannes added inline comments.



Comment at: lib/Tooling/ASTDiff/ASTDiff.cpp:171
+
+std::string TreeRoot::label(NodeId Id) const {
+  const Node  = getNode(Id);

arphaman wrote:
> I believe that this method that you call `label` actually represents the 
> `value` attribute that's described in the paper for the gumtree algorithm. Is 
> that right? If so, then this method name should be updated to reflect that.
Yes, good catch. Strangely, the gumtree implementation uses `label`. I think we 
should use `type` for node kinds and `value` for their actual value, in order 
to avoid confusion about what a label is.


https://reviews.llvm.org/D34329



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


[PATCH] D34329: [GSoC] Clang AST diffing

2017-06-20 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added inline comments.



Comment at: lib/Tooling/ASTDiff/ASTDiff.cpp:303
+/// Identifies a node in this subtree by its postorder offset.
+using SNodeId = int;
+

johannes wrote:
> arphaman wrote:
> > What's the difference between `SNodeId` and `NodeId`?
> NodeId is the preorder offset inside the root tree, starting at 0.
> SNodeId is the postorder offset within a subtree, starting at 1.
> Not sure if this irregularity can be improved upon easily, but I guess I can 
> mention it in the comments. 
Ok. It's fine to have two different types for them, but to avoid confusions I 
think that the code should be constructed in such a way that prohibits passing 
in `NodeId` to a function that expects `SNodeId` and vice-versa. You can wrap 
SNodeId in a typedef with an explicit constructor to achieve that goal, e.g.:

```
struct SNodeId {
  int Id;

  explicit SNodeId(int Id) : Id(Id) { };
}; 
```


https://reviews.llvm.org/D34329



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


[PATCH] D34329: [GSoC] Clang AST diffing

2017-06-20 Thread Johannes Altmanninger via Phabricator via cfe-commits
johannes added inline comments.



Comment at: lib/Tooling/ASTDiff/ASTDiff.cpp:303
+/// Identifies a node in this subtree by its postorder offset.
+using SNodeId = int;
+

arphaman wrote:
> What's the difference between `SNodeId` and `NodeId`?
NodeId is the preorder offset inside the root tree, starting at 0.
SNodeId is the postorder offset within a subtree, starting at 1.
Not sure if this irregularity can be improved upon easily, but I guess I can 
mention it in the comments. 


https://reviews.llvm.org/D34329



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


[PATCH] D34329: [GSoC] Clang AST diffing

2017-06-20 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added inline comments.



Comment at: lib/Tooling/ASTDiff/ASTDiff.cpp:171
+
+std::string TreeRoot::label(NodeId Id) const {
+  const Node  = getNode(Id);

I believe that this method that you call `label` actually represents the 
`value` attribute that's described in the paper for the gumtree algorithm. Is 
that right? If so, then this method name should be updated to reflect that.


https://reviews.llvm.org/D34329



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


[PATCH] D34329: [GSoC] Clang AST diffing

2017-06-20 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added inline comments.



Comment at: lib/Tooling/ASTDiff/ASTDiff.cpp:303
+/// Identifies a node in this subtree by its postorder offset.
+using SNodeId = int;
+

What's the difference between `SNodeId` and `NodeId`?


https://reviews.llvm.org/D34329



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


[PATCH] D34329: [GSoC] Clang AST diffing

2017-06-20 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added inline comments.



Comment at: lib/Tooling/ASTDiff/ASTDiff.cpp:474
+for (SNodeId D1 = LMD1 + 1; D1 <= Id1; ++D1) {
+  double DeletionCost = 1.0;
+  ForestDist[D1][LMD2] = ForestDist[D1 - 1][LMD2] + DeletionCost;

johannes wrote:
> arphaman wrote:
> > Are the `DeletionCost` and `InsertionCost` constants or are you planning to 
> > modify them in the future?
> I think they could be modified for minor improvements of the matching, but I 
> am probably not going to do so anytime soon. Maybe it is better to store them 
> at class scope as static const / constexpr?
Yeah, I suppose for now they should be declared as constants (the static const 
/ constexpr doesn't matter). They should probably be documented as well.



Comment at: lib/Tooling/ASTDiff/ASTDiff.cpp:693
+  H2 = L2.pop();
+  for (NodeId Id1 : H1)
+for (NodeId Id2 : H2)

johannes wrote:
> arphaman wrote:
> > Please wrap these loops in braces.
> Not sure if I got this right.
It looks better, thanks. Generally we prefer to use braces for `if`/`for`/etc. 
if they have more than one statement.


https://reviews.llvm.org/D34329



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


[PATCH] D34329: [GSoC] Clang AST diffing

2017-06-20 Thread Johannes Altmanninger via Phabricator via cfe-commits
johannes marked an inline comment as done.
johannes added a comment.

In https://reviews.llvm.org/D34329#785190, @arphaman wrote:

> Looking at the output of the tool, I have the following suggestion:
>
> - We should avoid implicit expressions (We don't need to see things like 
> `Insert ImplicitCastExpr(21) into BinaryOperator: *(22) at 0`). This can be 
> done in a follow-up patch though.


Ok, I will include that and other features in future patches.




Comment at: lib/Tooling/ASTDiff/ASTDiff.cpp:474
+for (SNodeId D1 = LMD1 + 1; D1 <= Id1; ++D1) {
+  double DeletionCost = 1.0;
+  ForestDist[D1][LMD2] = ForestDist[D1 - 1][LMD2] + DeletionCost;

arphaman wrote:
> Are the `DeletionCost` and `InsertionCost` constants or are you planning to 
> modify them in the future?
I think they could be modified for minor improvements of the matching, but I am 
probably not going to do so anytime soon. Maybe it is better to store them at 
class scope as static const / constexpr?



Comment at: lib/Tooling/ASTDiff/ASTDiff.cpp:693
+  H2 = L2.pop();
+  for (NodeId Id1 : H1)
+for (NodeId Id2 : H2)

arphaman wrote:
> Please wrap these loops in braces.
Not sure if I got this right.



Comment at: test/Tooling/clang-diff-basic.cpp:3
+// RUN: awk '/^.. dst/{f=1;next}/^.. end dst/{f=0}f' %s > %T/dst.cpp
+// RUN: clang-diff -no-compilation-database %T/src.cpp %T/dst.cpp
+// RUN: clang-diff -no-compilation-database %T/src.cpp %T/dst.cpp | FileCheck 
%s

arphaman wrote:
> I'd prefer it if we used something like `clang -E` and preprocessor to 
> generate the two files.
> 
> E.g.:
> 
> ```
> RUN: %clang_cc1 -E %s > %T/src.cpp
> RUN: %clang_cc1 -E %s -D DEST > %T/dst.cpp
> #ifndef DEST
> namespace src { };
> #else
> namespace dst { };
> #endif
> ```
Yes, much better!



Comment at: test/Tooling/clang-diff-basic.cpp:4
+// RUN: clang-diff -no-compilation-database %T/src.cpp %T/dst.cpp
+// RUN: clang-diff -no-compilation-database %T/src.cpp %T/dst.cpp | FileCheck 
%s
+

arphaman wrote:
> Why do you need two invocations of `clang-diff` with the same arguments?
That was unintentional, I removed it.


https://reviews.llvm.org/D34329



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


[PATCH] D34279: Fix release_40 build with MSVC (VS 2015)

2017-06-20 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

I still don't understand why this is breaking your build.

Assuming this is the line the first error refers to:

  for (unsigned BinOp : {G_ADD, G_SUB, G_MUL, G_AND, G_OR, G_XOR, G_SHL}) {

I don't see how converting G_ADD, even if it is an int, to unsigned would be a 
narrowing conversion.

I did a fresh checkout of LLVM and built with VS 19.00.2415.1 for x64:

  > svn export http://llvm.org/svn/llvm-project/llvm/trunk llvmtest
  > mkdir llvmtest\build
  > cd llvmtest\build
  > cmake -GNinja -DCMAKE_BUILD_TYPE=Release ..
  -- The C compiler identification is MSVC 19.0.24215.1
  -- The CXX compiler identification is MSVC 19.0.24215.1
  -- The ASM compiler identification is MSVC
  ...
  > ninja
  ...

And everything built fine.

There must be something different with your configuration.


https://reviews.llvm.org/D34279



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


[PATCH] D34342: [OpenCL] Fix code generation of function-scope constant samplers.

2017-06-20 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: test/CodeGenOpenCL/sampler.cl:62
+
+  const sampler_t const_smp = CLK_ADDRESS_CLAMP_TO_EDGE | 
CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_LINEAR;
+  // CHECK: [[CONST_SAMP:%[0-9]+]] = call %opencl.sampler_t addrspace(2)* 
@__translate_sampler_initializer(i32 35)

bader wrote:
> yaxunl wrote:
> > what if address of const_smp is taken and assigned to a pointer to 
> > sampler_t ? Do we have diagnosis in place?
> AFAIK, we have diagnostics for both:
> - declaration of a pointer to sampler
> - taking address of sampler variable
Btw, strangely I don't hit any unreachable and don't seem to have any static 
variable generated either. I was trying to compile this code on r305798:

  void fnc4smp(sampler_t s) {}
  kernel void foo(sampler_t smp_par) {
const sampler_t const_smp = 0;
fnc4smp(const_smp);
  }

This is the IR which is produced for me:

  %opencl.sampler_t = type opaque

  ; Function Attrs: noinline nounwind optnone
  define spir_func void @fnc4smp(%opencl.sampler_t addrspace(2)* %s) #0 {
  entry:
%s.addr = alloca %opencl.sampler_t addrspace(2)*, align 4
store %opencl.sampler_t addrspace(2)* %s, %opencl.sampler_t addrspace(2)** 
%s.addr, align 4
ret void
  }

  ; Function Attrs: noinline nounwind optnone
  define spir_kernel void @foo(%opencl.sampler_t addrspace(2)* %smp_par) #0 
!kernel_arg_addr_space !4 !kernel_arg_access_qual !5 !kernel_arg_type !6 
!kernel_arg_base_type !6 !kernel_arg_type_qual !7 {
  entry:
%smp_par.addr = alloca %opencl.sampler_t addrspace(2)*, align 4
%const_smp = alloca %opencl.sampler_t addrspace(2)*, align 4
store %opencl.sampler_t addrspace(2)* %smp_par, %opencl.sampler_t 
addrspace(2)** %smp_par.addr, align 4
%0 = call %opencl.sampler_t addrspace(2)* 
@__translate_sampler_initializer(i32 0)
store %opencl.sampler_t addrspace(2)* %0, %opencl.sampler_t addrspace(2)** 
%const_smp, align 4
%1 = load %opencl.sampler_t addrspace(2)*, %opencl.sampler_t addrspace(2)** 
%const_smp, align 4
call spir_func void @fnc4smp(%opencl.sampler_t addrspace(2)* %1)
ret void
  }

  declare %opencl.sampler_t addrspace(2)* @__translate_sampler_initializer(i32)


https://reviews.llvm.org/D34342



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


[PATCH] D34329: [GSoC] Clang AST diffing

2017-06-20 Thread Johannes Altmanninger via Phabricator via cfe-commits
johannes updated this revision to Diff 103208.
johannes marked 7 inline comments as done.

https://reviews.llvm.org/D34329

Files:
  include/clang/Tooling/ASTDiff/ASTDiff.h
  lib/Tooling/ASTDiff/ASTDiff.cpp
  lib/Tooling/ASTDiff/CMakeLists.txt
  lib/Tooling/CMakeLists.txt
  test/Tooling/clang-diff-basic.cpp
  tools/CMakeLists.txt
  tools/clang-diff/CMakeLists.txt
  tools/clang-diff/ClangDiff.cpp

Index: tools/clang-diff/ClangDiff.cpp
===
--- /dev/null
+++ tools/clang-diff/ClangDiff.cpp
@@ -0,0 +1,110 @@
+//===- ClangDiff.cpp - compare source files by AST nodes --*- C++ -*- -===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// This file implements a tool for syntax tree based comparison using
+// Tooling/ASTDiff.
+//
+//===--===//
+
+#include "clang/Tooling/ASTDiff/ASTDiff.h"
+#include "clang/Tooling/CommonOptionsParser.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/Support/CommandLine.h"
+
+using namespace llvm;
+using namespace clang;
+using namespace tooling;
+
+static cl::OptionCategory ClangDiffCategory("clang-diff options");
+
+static cl::opt
+DumpAST("ast-dump",
+cl::desc("Print the internal representation of the AST as JSON."),
+cl::init(false), cl::cat(ClangDiffCategory));
+
+static cl::opt NoCompilationDatabase(
+"no-compilation-database",
+cl::desc(
+"Do not attempt to load build settigns from a compilation database"),
+cl::init(false), cl::cat(ClangDiffCategory));
+
+static cl::opt SourcePath(cl::Positional, cl::desc(""),
+   cl::Required,
+   cl::cat(ClangDiffCategory));
+
+static cl::opt DestinationPath(cl::Positional,
+cl::desc(""),
+cl::Optional,
+cl::cat(ClangDiffCategory));
+
+static std::unique_ptr getAST(const StringRef Filename) {
+  std::string ErrorMessage;
+  std::unique_ptr Compilations;
+  if (!NoCompilationDatabase)
+Compilations =
+CompilationDatabase::autoDetectFromSource(Filename, ErrorMessage);
+  if (!Compilations) {
+if (!NoCompilationDatabase)
+  llvm::errs()
+  << "Error while trying to load a compilation database, running "
+ "without flags.\n"
+  << ErrorMessage;
+Compilations.reset(
+new FixedCompilationDatabase(".", std::vector()));
+  }
+  std::array Files = {{Filename}};
+  ClangTool Tool(*Compilations, Files);
+  std::vector ASTs;
+  Tool.buildASTs(ASTs);
+  if (ASTs.size() != Files.size())
+return nullptr;
+  return std::move(ASTs[0]);
+}
+
+int main(int argc, const char **argv) {
+  cl::HideUnrelatedOptions(ClangDiffCategory);
+  if (!cl::ParseCommandLineOptions(argc, argv)) {
+cl::PrintOptionValues();
+return 1;
+  }
+
+  if (DumpAST) {
+if (!DestinationPath.empty()) {
+  llvm::errs() << "Error: Please specify exactly one filename.\n";
+  return 1;
+}
+std::unique_ptr AST = getAST(SourcePath);
+if (!AST)
+  return 1;
+clang::diff::TreeRoot Tree(AST->getASTContext());
+Tree.printAsJson();
+return 0;
+  }
+
+  if (DestinationPath.empty()) {
+llvm::errs() << "Error: Exactly two paths are required.\n";
+return 1;
+  }
+
+  std::unique_ptr Src = getAST(SourcePath);
+  std::unique_ptr Dst = getAST(DestinationPath);
+  if (!Src || !Dst)
+return 1;
+
+  diff::TreeRoot T1(Src->getASTContext());
+  diff::TreeRoot T2(Dst->getASTContext());
+  diff::ASTDiff DiffTool(T1, T2);
+  diff::Mapping M = DiffTool.computeMapping();
+  M.printMapping();
+  auto Changes = DiffTool.computeChanges(M);
+  for (const auto  : Changes)
+DiffTool.printChange(C);
+
+  return 0;
+}
Index: tools/clang-diff/CMakeLists.txt
===
--- /dev/null
+++ tools/clang-diff/CMakeLists.txt
@@ -0,0 +1,13 @@
+set(LLVM_LINK_COMPONENTS
+  Support
+  )
+
+add_clang_executable(clang-diff
+  ClangDiff.cpp
+  )
+
+target_link_libraries(clang-diff
+  clangFrontend
+  clangTooling
+  clangToolingASTDiff
+  )
Index: tools/CMakeLists.txt
===
--- tools/CMakeLists.txt
+++ tools/CMakeLists.txt
@@ -2,6 +2,7 @@
 
 add_clang_subdirectory(diagtool)
 add_clang_subdirectory(driver)
+add_clang_subdirectory(clang-diff)
 add_clang_subdirectory(clang-format)
 add_clang_subdirectory(clang-format-vs)
 add_clang_subdirectory(clang-fuzzer)
Index: test/Tooling/clang-diff-basic.cpp

[PATCH] D31187: Fix removal of out-of-line definitions.

2017-06-20 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev closed this revision.
v.g.vassilev added a comment.

Landed in r305799. I would like to test it and I think that should be possible 
as soon as I land some interpreter infrastructure which is on my TODO list.


https://reviews.llvm.org/D31187



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


r305799 - D31187: Fix removal of out-of-line definitions.

2017-06-20 Thread Vassil Vassilev via cfe-commits
Author: vvassilev
Date: Tue Jun 20 09:59:57 2017
New Revision: 305799

URL: http://llvm.org/viewvc/llvm-project?rev=305799=rev
Log:
D31187: Fix removal of out-of-line definitions.

Consider:

struct MyClass {
  void f() {}
}
MyClass::f(){} // expected error redefinition of f. #1

Some clients (eg. cling) need to call removeDecl for the redefined (#1) decl.

This patch enables us to remove the lookup entry is registered in the semantic
decl context and not in the primary decl context of the lexical decl context
where we currently are trying to remove it from.

It is not trivial to test this piece and writing a full-blown unit test seems
too much.

Modified:
cfe/trunk/lib/AST/DeclBase.cpp

Modified: cfe/trunk/lib/AST/DeclBase.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclBase.cpp?rev=305799=305798=305799=diff
==
--- cfe/trunk/lib/AST/DeclBase.cpp (original)
+++ cfe/trunk/lib/AST/DeclBase.cpp Tue Jun 20 09:59:57 2017
@@ -1352,7 +1352,7 @@ void DeclContext::removeDecl(Decl *D) {
 // Remove only decls that have a name
 if (!ND->getDeclName()) return;
 
-auto *DC = this;
+auto *DC = D->getDeclContext();
 do {
   StoredDeclsMap *Map = DC->getPrimaryContext()->LookupPtr;
   if (Map) {


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


[PATCH] D34024: [OpenCL] Diagnose scoped address-space qualified variables

2017-06-20 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL305798: [OpenCL] Diagnose scoped address-space qualified 
variables (authored by stulova).

Changed prior to commit:
  https://reviews.llvm.org/D34024?vs=101872=103207#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34024

Files:
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/lib/Sema/SemaDecl.cpp
  cfe/trunk/test/SemaOpenCL/storageclass.cl


Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8311,6 +8311,9 @@
   "vector component access has invalid length %0.  Supported: 1,2,3,4,8,16.">;
 def err_opencl_function_variable : Error<
   "%select{non-kernel function|function scope}0 variable cannot be declared in 
%1 address space">;
+def err_opencl_addrspace_scope : Error<
+  "variables in the %0 address space can only be declared in the outermost "
+  "scope of a kernel function">;
 def err_static_function_scope : Error<
   "variables in function scope cannot be declared static">;
 def err_opencl_bitfields : Error<
Index: cfe/trunk/test/SemaOpenCL/storageclass.cl
===
--- cfe/trunk/test/SemaOpenCL/storageclass.cl
+++ cfe/trunk/test/SemaOpenCL/storageclass.cl
@@ -13,6 +13,11 @@
   constant int L1 = 0;
   local int L2;
 
+  if (true) {
+local int L1; // expected-error {{variables in the local address space can 
only be declared in the outermost scope of a kernel function}}
+constant int L1 = 42; // expected-error {{variables in the constant 
address space can only be declared in the outermost scope of a kernel function}}
+  }
+
   auto int L3 = 7;// expected-error{{OpenCL 
version 1.2 does not support the 'auto' storage class specifier}}
   global int L4;  // expected-error{{function 
scope variable cannot be declared in global address space}}
   __attribute__((address_space(100))) int L5; // expected-error{{automatic 
variable qualified with an invalid address space}}
Index: cfe/trunk/lib/Sema/SemaDecl.cpp
===
--- cfe/trunk/lib/Sema/SemaDecl.cpp
+++ cfe/trunk/lib/Sema/SemaDecl.cpp
@@ -7260,11 +7260,11 @@
 NewVD->setInvalidDecl();
 return;
   }
-  // OpenCL v1.1 s6.5.2 and s6.5.3 no local or constant variables
-  // in functions.
   if (T.getAddressSpace() == LangAS::opencl_constant ||
   T.getAddressSpace() == LangAS::opencl_local) {
 FunctionDecl *FD = getCurFunctionDecl();
+// OpenCL v1.1 s6.5.2 and s6.5.3: no local or constant variables
+// in functions.
 if (FD && !FD->hasAttr()) {
   if (T.getAddressSpace() == LangAS::opencl_constant)
 Diag(NewVD->getLocation(), diag::err_opencl_function_variable)
@@ -7275,6 +7275,20 @@
   NewVD->setInvalidDecl();
   return;
 }
+// OpenCL v2.0 s6.5.2 and s6.5.3: local and constant variables must be
+// in the outermost scope of a kernel function.
+if (FD && FD->hasAttr()) {
+  if (!getCurScope()->isFunctionScope()) {
+if (T.getAddressSpace() == LangAS::opencl_constant)
+  Diag(NewVD->getLocation(), diag::err_opencl_addrspace_scope)
+  << "constant";
+else
+  Diag(NewVD->getLocation(), diag::err_opencl_addrspace_scope)
+  << "local";
+NewVD->setInvalidDecl();
+return;
+  }
+}
   } else if (T.getAddressSpace() != LangAS::Default) {
 // Do not allow other address spaces on automatic variable.
 Diag(NewVD->getLocation(), diag::err_as_qualified_auto_decl) << 1;


Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8311,6 +8311,9 @@
   "vector component access has invalid length %0.  Supported: 1,2,3,4,8,16.">;
 def err_opencl_function_variable : Error<
   "%select{non-kernel function|function scope}0 variable cannot be declared in %1 address space">;
+def err_opencl_addrspace_scope : Error<
+  "variables in the %0 address space can only be declared in the outermost "
+  "scope of a kernel function">;
 def err_static_function_scope : Error<
   "variables in function scope cannot be declared static">;
 def err_opencl_bitfields : Error<
Index: cfe/trunk/test/SemaOpenCL/storageclass.cl
===
--- cfe/trunk/test/SemaOpenCL/storageclass.cl
+++ cfe/trunk/test/SemaOpenCL/storageclass.cl
@@ -13,6 +13,11 @@
   constant int L1 = 0;
   local int L2;
 
+  if 

r305798 - [OpenCL] Diagnose scoped address-space qualified variables

2017-06-20 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Tue Jun 20 09:50:45 2017
New Revision: 305798

URL: http://llvm.org/viewvc/llvm-project?rev=305798=rev
Log:
[OpenCL] Diagnose scoped address-space qualified variables

Produce an error if variables qualified with a local or
a constant address space are not declared in the outermost
scope of a kernel.

Patch by Simon Perretta.

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


Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaOpenCL/storageclass.cl

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=305798=305797=305798=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Jun 20 09:50:45 
2017
@@ -8311,6 +8311,9 @@ def err_opencl_ext_vector_component_inva
   "vector component access has invalid length %0.  Supported: 1,2,3,4,8,16.">;
 def err_opencl_function_variable : Error<
   "%select{non-kernel function|function scope}0 variable cannot be declared in 
%1 address space">;
+def err_opencl_addrspace_scope : Error<
+  "variables in the %0 address space can only be declared in the outermost "
+  "scope of a kernel function">;
 def err_static_function_scope : Error<
   "variables in function scope cannot be declared static">;
 def err_opencl_bitfields : Error<

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=305798=305797=305798=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Jun 20 09:50:45 2017
@@ -7260,11 +7260,11 @@ void Sema::CheckVariableDeclarationType(
 NewVD->setInvalidDecl();
 return;
   }
-  // OpenCL v1.1 s6.5.2 and s6.5.3 no local or constant variables
-  // in functions.
   if (T.getAddressSpace() == LangAS::opencl_constant ||
   T.getAddressSpace() == LangAS::opencl_local) {
 FunctionDecl *FD = getCurFunctionDecl();
+// OpenCL v1.1 s6.5.2 and s6.5.3: no local or constant variables
+// in functions.
 if (FD && !FD->hasAttr()) {
   if (T.getAddressSpace() == LangAS::opencl_constant)
 Diag(NewVD->getLocation(), diag::err_opencl_function_variable)
@@ -7275,6 +7275,20 @@ void Sema::CheckVariableDeclarationType(
   NewVD->setInvalidDecl();
   return;
 }
+// OpenCL v2.0 s6.5.2 and s6.5.3: local and constant variables must be
+// in the outermost scope of a kernel function.
+if (FD && FD->hasAttr()) {
+  if (!getCurScope()->isFunctionScope()) {
+if (T.getAddressSpace() == LangAS::opencl_constant)
+  Diag(NewVD->getLocation(), diag::err_opencl_addrspace_scope)
+  << "constant";
+else
+  Diag(NewVD->getLocation(), diag::err_opencl_addrspace_scope)
+  << "local";
+NewVD->setInvalidDecl();
+return;
+  }
+}
   } else if (T.getAddressSpace() != LangAS::Default) {
 // Do not allow other address spaces on automatic variable.
 Diag(NewVD->getLocation(), diag::err_as_qualified_auto_decl) << 1;

Modified: cfe/trunk/test/SemaOpenCL/storageclass.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/storageclass.cl?rev=305798=305797=305798=diff
==
--- cfe/trunk/test/SemaOpenCL/storageclass.cl (original)
+++ cfe/trunk/test/SemaOpenCL/storageclass.cl Tue Jun 20 09:50:45 2017
@@ -13,6 +13,11 @@ void kernel foo(int x) {
   constant int L1 = 0;
   local int L2;
 
+  if (true) {
+local int L1; // expected-error {{variables in the local address space can 
only be declared in the outermost scope of a kernel function}}
+constant int L1 = 42; // expected-error {{variables in the constant 
address space can only be declared in the outermost scope of a kernel function}}
+  }
+
   auto int L3 = 7;// expected-error{{OpenCL 
version 1.2 does not support the 'auto' storage class specifier}}
   global int L4;  // expected-error{{function 
scope variable cannot be declared in global address space}}
   __attribute__((address_space(100))) int L5; // expected-error{{automatic 
variable qualified with an invalid address space}}


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


[PATCH] D34287: Moved code hanlding precompiled preamble out of the ASTUnit.

2017-06-20 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added inline comments.



Comment at: include/clang/Frontend/PrecompiledPreamble.h:124
+/// CanReusePreamble + AddImplicitPreamble to make use of it.
+class PrecompiledPreamble {
+public:

ilya-biryukov wrote:
> klimek wrote:
> > If a user doesn't care about the things above this class, can we move those 
> > into an extra header?
> Do you have any suggestions of where to put it and how to call it?
> I didn't think it's a good idea to put something like 'PreambleFileHash.h' 
> and 'TempPCHFile.h' into 'include/clang/Frontend/'. (Given that they are 
> essential an implementation detail of PrecompiledPreamble, exposing them in 
> public include folders seems like a bad idea).
TempPCHFile looks like something we just want to put into the .cc file and 
store as a unique_ptr.
PreambleFileHash seems fine as an extra header.



Comment at: include/clang/Frontend/PrecompiledPreamble.h:157-160
+  /// We don't expose PCHFile to avoid changing interface when we'll add an
+  /// in-memory PCH, so we declare this function as friend so that it has 
access
+  /// to PCHFile field.
+  friend void AddImplicitPreamble(CompilerInvocation ,

ilya-biryukov wrote:
> klimek wrote:
> > Why not make it a member instead?
> To keep BuildPreamble, CanReusePreamble and AddImplicitPreamble close to each 
> other.
> I.e. PrecompiledPreamble only stores data used by these functions.
> 
> We could make all of those members, of course. Do you think that would make 
> API better?
Generally, if these are closely coupled to implementation details of 
PrecompiledPreample, I think that coupling is strong enough to warrant making 
them members.
On the other hand, making some functions members, and others non-members, and 
putting them next to each other in the .cc file also would work.


https://reviews.llvm.org/D34287



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


[PATCH] D34263: [preprocessor] When preprocessor option 'SingleFileParseMode' is enabled, parse all directive blocks if the condition uses undefined macros

2017-06-20 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL305797: [preprocessor] When preprocessor option 
'SingleFileParseMode' is enabled, parseā€¦ (authored by akirtzidis).

Changed prior to commit:
  https://reviews.llvm.org/D34263?vs=103067=103206#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34263

Files:
  cfe/trunk/include/clang/Lex/Preprocessor.h
  cfe/trunk/include/clang/Lex/PreprocessorOptions.h
  cfe/trunk/lib/Lex/PPDirectives.cpp
  cfe/trunk/lib/Lex/PPExpressions.cpp
  cfe/trunk/test/Index/singe-file-parse.m
  cfe/trunk/test/Index/single-file-parse.m

Index: cfe/trunk/include/clang/Lex/PreprocessorOptions.h
===
--- cfe/trunk/include/clang/Lex/PreprocessorOptions.h
+++ cfe/trunk/include/clang/Lex/PreprocessorOptions.h
@@ -96,6 +96,10 @@
   std::string TokenCache;
 
   /// When enabled, preprocessor is in a mode for parsing a single file only.
+  ///
+  /// Disables #includes of other files and if there are unresolved identifiers
+  /// in preprocessor directive conditions it causes all blocks to be parsed so
+  /// that the client can get the maximum amount of information from the parser.
   bool SingleFileParseMode = false;
 
   /// When enabled, the preprocessor will construct editor placeholder tokens.
Index: cfe/trunk/include/clang/Lex/Preprocessor.h
===
--- cfe/trunk/include/clang/Lex/Preprocessor.h
+++ cfe/trunk/include/clang/Lex/Preprocessor.h
@@ -1835,11 +1835,20 @@
   /// \brief A fast PTH version of SkipExcludedConditionalBlock.
   void PTHSkipExcludedConditionalBlock();
 
+  /// Information about the result for evaluating an expression for a
+  /// preprocessor directive.
+  struct DirectiveEvalResult {
+/// Whether the expression was evaluated as true or not.
+bool Conditional;
+/// True if the expression contained identifiers that were undefined.
+bool IncludedUndefinedIds;
+  };
+
   /// \brief Evaluate an integer constant expression that may occur after a
-  /// \#if or \#elif directive and return it as a bool.
+  /// \#if or \#elif directive and return a \p DirectiveEvalResult object.
   ///
   /// If the expression is equivalent to "!defined(X)" return X in IfNDefMacro.
-  bool EvaluateDirectiveExpression(IdentifierInfo *);
+  DirectiveEvalResult EvaluateDirectiveExpression(IdentifierInfo *);
 
   /// \brief Install the standard preprocessor pragmas:
   /// \#pragma GCC poison/system_header/dependency and \#pragma once.
Index: cfe/trunk/test/Index/single-file-parse.m
===
--- cfe/trunk/test/Index/single-file-parse.m
+++ cfe/trunk/test/Index/single-file-parse.m
@@ -0,0 +1,111 @@
+// RUN: c-index-test -single-file-parse %s | FileCheck %s
+
+#include 
+
+// CHECK-NOT: TypedefDecl=intptr_t
+
+// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=MyCls
+@interface MyCls
+// CHECK: [[@LINE+1]]:8: ObjCInstanceMethodDecl=some_meth
+-(void)some_meth;
+@end
+
+#if 1
+// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test1
+@interface Test1 @end
+#else
+// CHECK-NOT: [[@LINE+1]]:12:
+@interface Test2 @end
+#endif
+
+#if 0
+// CHECK-NOT: [[@LINE+1]]:12:
+@interface Test3 @end
+#else
+// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test4
+@interface Test4 @end
+#endif
+
+#if SOMETHING_NOT_DEFINED
+// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test5
+@interface Test5 @end
+#else
+// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test6
+@interface Test6 @end
+#endif
+
+#define SOMETHING_DEFINED 1
+#if SOMETHING_DEFINED
+// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test7
+@interface Test7 @end
+#else
+// CHECK-NOT: [[@LINE+1]]:12:
+@interface Test8 @end
+#endif
+
+#if defined(SOMETHING_NOT_DEFINED)
+// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test9
+@interface Test9 @end
+#else
+// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test10
+@interface Test10 @end
+#endif
+
+#if defined(SOMETHING_DEFINED)
+// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test11
+@interface Test11 @end
+#else
+// CHECK-NOT: [[@LINE+1]]:12:
+@interface Test12 @end
+#endif
+
+#if SOMETHING_NOT_DEFINED1
+// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test13
+@interface Test13 @end
+#elif SOMETHING_NOT_DEFINED2
+// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test14
+@interface Test14 @end
+#else
+// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test15
+@interface Test15 @end
+#endif
+
+#ifdef SOMETHING_NOT_DEFINED
+// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test19
+@interface Test19 @end
+#else
+// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test20
+@interface Test20 @end
+#endif
+
+#ifdef SOMETHING_DEFINED
+// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test21
+@interface Test21 @end
+#else
+// CHECK-NOT: [[@LINE+1]]:12:
+@interface Test22 @end
+#endif
+
+#ifndef SOMETHING_NOT_DEFINED
+// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test23
+@interface Test23 @end
+#else
+// CHECK: [[@LINE+1]]:12: ObjCInterfaceDecl=Test24
+@interface 

r305797 - [preprocessor] When preprocessor option 'SingleFileParseMode' is enabled, parse all directive blocks if the condition uses undefined macros

2017-06-20 Thread Argyrios Kyrtzidis via cfe-commits
Author: akirtzidis
Date: Tue Jun 20 09:36:58 2017
New Revision: 305797

URL: http://llvm.org/viewvc/llvm-project?rev=305797=rev
Log:
[preprocessor] When preprocessor option 'SingleFileParseMode' is enabled, parse 
all directive blocks if the condition uses undefined macros

This is useful for being able to parse the preprocessor directive blocks even 
if the header, that defined the macro that is checked, hasn't been included.

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

Added:
cfe/trunk/test/Index/single-file-parse.m
Removed:
cfe/trunk/test/Index/singe-file-parse.m
Modified:
cfe/trunk/include/clang/Lex/Preprocessor.h
cfe/trunk/include/clang/Lex/PreprocessorOptions.h
cfe/trunk/lib/Lex/PPDirectives.cpp
cfe/trunk/lib/Lex/PPExpressions.cpp

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=305797=305796=305797=diff
==
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Tue Jun 20 09:36:58 2017
@@ -1835,11 +1835,20 @@ private:
   /// \brief A fast PTH version of SkipExcludedConditionalBlock.
   void PTHSkipExcludedConditionalBlock();
 
+  /// Information about the result for evaluating an expression for a
+  /// preprocessor directive.
+  struct DirectiveEvalResult {
+/// Whether the expression was evaluated as true or not.
+bool Conditional;
+/// True if the expression contained identifiers that were undefined.
+bool IncludedUndefinedIds;
+  };
+
   /// \brief Evaluate an integer constant expression that may occur after a
-  /// \#if or \#elif directive and return it as a bool.
+  /// \#if or \#elif directive and return a \p DirectiveEvalResult object.
   ///
   /// If the expression is equivalent to "!defined(X)" return X in IfNDefMacro.
-  bool EvaluateDirectiveExpression(IdentifierInfo *);
+  DirectiveEvalResult EvaluateDirectiveExpression(IdentifierInfo 
*);
 
   /// \brief Install the standard preprocessor pragmas:
   /// \#pragma GCC poison/system_header/dependency and \#pragma once.

Modified: cfe/trunk/include/clang/Lex/PreprocessorOptions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PreprocessorOptions.h?rev=305797=305796=305797=diff
==
--- cfe/trunk/include/clang/Lex/PreprocessorOptions.h (original)
+++ cfe/trunk/include/clang/Lex/PreprocessorOptions.h Tue Jun 20 09:36:58 2017
@@ -96,6 +96,10 @@ public:
   std::string TokenCache;
 
   /// When enabled, preprocessor is in a mode for parsing a single file only.
+  ///
+  /// Disables #includes of other files and if there are unresolved identifiers
+  /// in preprocessor directive conditions it causes all blocks to be parsed so
+  /// that the client can get the maximum amount of information from the 
parser.
   bool SingleFileParseMode = false;
 
   /// When enabled, the preprocessor will construct editor placeholder tokens.

Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=305797=305796=305797=diff
==
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Tue Jun 20 09:36:58 2017
@@ -538,7 +538,7 @@ void Preprocessor::SkipExcludedCondition
   assert(CurPPLexer->LexingRawMode && "We have to be skipping here!");
   CurPPLexer->LexingRawMode = false;
   IdentifierInfo *IfNDefMacro = nullptr;
-  const bool CondValue = EvaluateDirectiveExpression(IfNDefMacro);
+  const bool CondValue = 
EvaluateDirectiveExpression(IfNDefMacro).Conditional;
   CurPPLexer->LexingRawMode = true;
   if (Callbacks) {
 const SourceLocation CondEnd = CurPPLexer->getSourceLocation();
@@ -635,7 +635,7 @@ void Preprocessor::PTHSkipExcludedCondit
 // Evaluate the condition of the #elif.
 IdentifierInfo *IfNDefMacro = nullptr;
 CurPTHLexer->ParsingPreprocessorDirective = true;
-bool ShouldEnter = EvaluateDirectiveExpression(IfNDefMacro);
+bool ShouldEnter = EvaluateDirectiveExpression(IfNDefMacro).Conditional;
 CurPTHLexer->ParsingPreprocessorDirective = false;
 
 // If this condition is true, enter it!
@@ -2654,7 +2654,13 @@ void Preprocessor::HandleIfdefDirective(
   }
 
   // Should we include the stuff contained by this directive?
-  if (!MI == isIfndef) {
+  if (PPOpts->SingleFileParseMode && !MI) {
+// In 'single-file-parse mode' undefined identifiers trigger parsing of all
+// the directive blocks.
+CurPPLexer->pushConditionalLevel(DirectiveTok.getLocation(),
+ /*wasskip*/true, /*foundnonskip*/false,
+ /*foundelse*/false);
+  } else if (!MI == 

r305796 - [OpenCL] Fix OpenCL and SPIR version metadata generation.

2017-06-20 Thread Alexey Bader via cfe-commits
Author: bader
Date: Tue Jun 20 09:30:18 2017
New Revision: 305796

URL: http://llvm.org/viewvc/llvm-project?rev=305796=rev
Log:
[OpenCL] Fix OpenCL and SPIR version metadata generation.

Summary: OpenCL and SPIR version metadata must be generated once per module 
instead of once per mangled global value.

Reviewers: Anastasia, yaxunl

Reviewed By: Anastasia

Subscribers: ahatanak, cfe-commits

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

Modified:
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.h
cfe/trunk/lib/CodeGen/TargetInfo.cpp
cfe/trunk/test/CodeGenOpenCL/spir_version.cl

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=305796=305795=305796=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Tue Jun 20 09:30:18 2017
@@ -506,6 +506,26 @@ void CodeGenModule::Release() {
   LangOpts.CUDADeviceFlushDenormalsToZero ? 1 : 0);
   }
 
+  // Emit OpenCL specific module metadata: OpenCL/SPIR version.
+  if (LangOpts.OpenCL) {
+EmitOpenCLMetadata();
+// Emit SPIR version.
+if (getTriple().getArch() == llvm::Triple::spir ||
+getTriple().getArch() == llvm::Triple::spir64) {
+  // SPIR v2.0 s2.12 - The SPIR version used by the module is stored in the
+  // opencl.spir.version named metadata.
+  llvm::Metadata *SPIRVerElts[] = {
+  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
+  Int32Ty, LangOpts.OpenCLVersion / 100)),
+  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
+  Int32Ty, (LangOpts.OpenCLVersion / 100 > 1) ? 0 : 2))};
+  llvm::NamedMDNode *SPIRVerMD =
+  TheModule.getOrInsertNamedMetadata("opencl.spir.version");
+  llvm::LLVMContext  = TheModule.getContext();
+  SPIRVerMD->addOperand(llvm::MDNode::get(Ctx, SPIRVerElts));
+}
+  }
+
   if (uint32_t PLevel = Context.getLangOpts().PICLevel) {
 assert(PLevel < 3 && "Invalid PIC Level");
 getModule().setPICLevel(static_cast(PLevel));
@@ -529,6 +549,20 @@ void CodeGenModule::Release() {
   EmitTargetMetadata();
 }
 
+void CodeGenModule::EmitOpenCLMetadata() {
+  // SPIR v2.0 s2.13 - The OpenCL version used by the module is stored in the
+  // opencl.ocl.version named metadata node.
+  llvm::Metadata *OCLVerElts[] = {
+  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
+  Int32Ty, LangOpts.OpenCLVersion / 100)),
+  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
+  Int32Ty, (LangOpts.OpenCLVersion % 100) / 10))};
+  llvm::NamedMDNode *OCLVerMD =
+  TheModule.getOrInsertNamedMetadata("opencl.ocl.version");
+  llvm::LLVMContext  = TheModule.getContext();
+  OCLVerMD->addOperand(llvm::MDNode::get(Ctx, OCLVerElts));
+}
+
 void CodeGenModule::UpdateCompletedType(const TagDecl *TD) {
   // Make sure that this type is translated.
   Types.UpdateCompletedType(TD);

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=305796=305795=305796=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Tue Jun 20 09:30:18 2017
@@ -1321,6 +1321,9 @@ private:
   /// Emits target specific Metadata for global declarations.
   void EmitTargetMetadata();
 
+  /// Emits OpenCL specific Metadata e.g. OpenCL version.
+  void EmitOpenCLMetadata();
+
   /// Emit the llvm.gcov metadata used to tell LLVM where to emit the .gcno and
   /// .gcda files in a way that persists in .bc files.
   void EmitCoverageFile();

Modified: cfe/trunk/lib/CodeGen/TargetInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=305796=305795=305796=diff
==
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp Tue Jun 20 09:30:18 2017
@@ -7344,8 +7344,6 @@ public:
 };
 }
 
-static void appendOpenCLVersionMD (CodeGen::CodeGenModule );
-
 void AMDGPUTargetCodeGenInfo::setTargetAttributes(
 const Decl *D,
 llvm::GlobalValue *GV,
@@ -7402,8 +7400,6 @@ void AMDGPUTargetCodeGenInfo::setTargetA
 if (NumVGPR != 0)
   F->addFnAttr("amdgpu-num-vgpr", llvm::utostr(NumVGPR));
   }
-
-  appendOpenCLVersionMD(M);
 }
 
 unsigned AMDGPUTargetCodeGenInfo::getOpenCLKernelCallingConv() const {
@@ -8074,8 +8070,6 @@ class SPIRTargetCodeGenInfo : public Tar
 public:
   SPIRTargetCodeGenInfo(CodeGen::CodeGenTypes )
 : TargetCodeGenInfo(new DefaultABIInfo(CGT)) {}
-  void emitTargetMD(const Decl *D, llvm::GlobalValue *GV,
-CodeGen::CodeGenModule ) const override;
   unsigned 

[PATCH] D34235: [OpenCL] Fix OpenCL and SPIR version metadata generation.

2017-06-20 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia accepted this revision.
Anastasia added a comment.
This revision is now accepted and ready to land.

LGTM! Thanks!


https://reviews.llvm.org/D34235



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


[PATCH] D33719: Add _Float16 as a C/C++ source language type

2017-06-20 Thread Sjoerd Meijer via Phabricator via cfe-commits
SjoerdMeijer updated this revision to Diff 103201.
SjoerdMeijer edited the summary of this revision.
SjoerdMeijer added a comment.

I have added a fix for mixed __fp16 and _Float16 expressions: _Float16 type is 
converted to __fp16 type and then the operation is completed as if both 
operands were of __fp16 type. I've implemented this by adding _Float16 to the 
FloatingRank. By declaring Float16Rank to be smaller than HalfRank, we 
automatically get the promotions to __fp16 when required. I thought this 
approach is more elegant than adding more special cases in the floating point 
conversion functions.

I've added another test case ##test/Frontend/float16.cpp## that checks the AST 
(this is in addition to the codegen test that we already have). This test also 
checks mixed type expressions.


https://reviews.llvm.org/D33719

Files:
  include/clang-c/Index.h
  include/clang/AST/ASTContext.h
  include/clang/AST/BuiltinTypes.def
  include/clang/Basic/Specifiers.h
  include/clang/Basic/TokenKinds.def
  include/clang/Lex/LiteralSupport.h
  include/clang/Sema/DeclSpec.h
  include/clang/Serialization/ASTBitCodes.h
  lib/AST/ASTContext.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/MicrosoftMangle.cpp
  lib/AST/NSAPI.cpp
  lib/AST/StmtPrinter.cpp
  lib/AST/Type.cpp
  lib/AST/TypeLoc.cpp
  lib/Analysis/PrintfFormatString.cpp
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CGExprScalar.cpp
  lib/CodeGen/CodeGenTypes.cpp
  lib/CodeGen/ItaniumCXXABI.cpp
  lib/Format/FormatToken.cpp
  lib/Index/USRGeneration.cpp
  lib/Lex/LiteralSupport.cpp
  lib/Parse/ParseDecl.cpp
  lib/Parse/ParseExpr.cpp
  lib/Parse/ParseExprCXX.cpp
  lib/Parse/ParseTentative.cpp
  lib/Sema/DeclSpec.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaTemplateVariadic.cpp
  lib/Sema/SemaType.cpp
  lib/Serialization/ASTCommon.cpp
  lib/Serialization/ASTReader.cpp
  test/CodeGenCXX/float16-declarations.cpp
  test/Frontend/float16.cpp
  test/Lexer/half-literal.cpp
  tools/libclang/CXType.cpp

Index: tools/libclang/CXType.cpp
===
--- tools/libclang/CXType.cpp
+++ tools/libclang/CXType.cpp
@@ -53,6 +53,7 @@
 BTCASE(Float);
 BTCASE(Double);
 BTCASE(LongDouble);
+BTCASE(Float16);
 BTCASE(Float128);
 BTCASE(NullPtr);
 BTCASE(Overload);
@@ -520,7 +521,7 @@
 TKIND(Char_U);
 TKIND(UChar);
 TKIND(Char16);
-TKIND(Char32);  
+TKIND(Char32);
 TKIND(UShort);
 TKIND(UInt);
 TKIND(ULong);
@@ -538,6 +539,7 @@
 TKIND(Float);
 TKIND(Double);
 TKIND(LongDouble);
+TKIND(Float16);
 TKIND(Float128);
 TKIND(NullPtr);
 TKIND(Overload);
Index: test/Lexer/half-literal.cpp
===
--- test/Lexer/half-literal.cpp
+++ test/Lexer/half-literal.cpp
@@ -1,3 +1,6 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s
 float a = 1.0h; // expected-error{{invalid suffix 'h' on floating constant}}
 float b = 1.0H; // expected-error{{invalid suffix 'H' on floating constant}}
+
+_Float16 c = 1.f166; // expected-error{{invalid suffix 'f166' on floating constant}}
+_Float16 d = 1.f1;   // expected-error{{invalid suffix 'f1' on floating constant}}
Index: test/Frontend/float16.cpp
===
--- /dev/null
+++ test/Frontend/float16.cpp
@@ -0,0 +1,297 @@
+// RUN: %clang_cc1 -std=c++11 -ast-dump %s | FileCheck %s
+// RUN: %clang_cc1 -std=c++11 -ast-dump -fnative-half-type %s | FileCheck %s --check-prefix=CHECK-NATIVE
+
+/*  Various contexts where type _Float16 can appear. */
+
+/*  Namespace */
+namespace {
+  _Float16 f1n;
+  _Float16 f2n = 33.f16;
+  _Float16 arr1n[10];
+  _Float16 arr2n[] = { 1.2, 3.0, 3.e4 };
+  const volatile _Float16 func1n(const _Float16 ) {
+return arg + f2n + arr1n[4] - arr2n[1];
+  }
+}
+
+//CHECK: |-NamespaceDecl
+//CHECK: | |-VarDecl {{.*}} f1n '_Float16'
+//CHECK: | |-VarDecl {{.*}} f2n '_Float16' cinit
+//CHECK: | | `-FloatingLiteral {{.*}} '_Float16' 3.30e+01
+//CHECK: | |-VarDecl {{.*}} arr1n '_Float16 [10]'
+//CHECK: | |-VarDecl {{.*}} arr2n '_Float16 [3]' cinit
+//CHECK: | | `-InitListExpr {{.*}} '_Float16 [3]'
+//CHECK: | |   |-ImplicitCastExpr {{.*}} '_Float16' 
+//CHECK: | |   | `-FloatingLiteral {{.*}} 'double' 1.20e+00
+//CHECK: | |   |-ImplicitCastExpr {{.*}} '_Float16' 
+//CHECK: | |   | `-FloatingLiteral {{.*}} 'double' 3.00e+00
+//CHECK: | |   `-ImplicitCastExpr {{.*}} '_Float16' 
+//CHECK: | | `-FloatingLiteral {{.*}} 'double' 3.00e+04
+//CHECK: | `-FunctionDecl {{.*}} func1n 'const volatile _Float16 (const _Float16 &)'
+
+/* File */
+_Float16 f1f;
+_Float16 f2f = 32.4;
+_Float16 arr1f[10];
+_Float16 arr2f[] = { -1.2, -3.0, -3.e4 };
+_Float16 func1f(_Float16 arg);
+
+//CHECK: |-VarDecl {{.*}} f1f '_Float16'
+//CHECK: |-VarDecl {{.*}} f2f '_Float16' cinit
+//CHECK: | `-ImplicitCastExpr {{.*}} '_Float16' 
+//CHECK: |   `-FloatingLiteral {{.*}} 'double' 

  1   2   >