r330927 - Make test more platform neutral

2018-04-26 Thread Serge Pavlov via cfe-commits
Author: sepavloff
Date: Thu Apr 26 01:08:25 2018
New Revision: 330927

URL: http://llvm.org/viewvc/llvm-project?rev=330927&view=rev
Log:
Make test more platform neutral

Modified:
cfe/trunk/test/Driver/config-file4.c

Modified: cfe/trunk/test/Driver/config-file4.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/config-file4.c?rev=330927&r1=330926&r2=330927&view=diff
==
--- cfe/trunk/test/Driver/config-file4.c (original)
+++ cfe/trunk/test/Driver/config-file4.c Thu Apr 26 01:08:25 2018
@@ -1,2 +1,2 @@
 // RUN: %clang --config %S/Inputs/empty.cfg -Wall -Wextra -Wformat 
-Wstrict-aliasing -Wshadow -Wpacked -Winline -Wimplicit-function-declaration -c 
%s -O2 -o /dev/null -v 2>&1 | FileCheck %s -check-prefix PR37196
-// PR37196: Configuration file: {{.*}}/empty.cfg
+// PR37196: Configuration file: {{.*}}empty.cfg


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


[PATCH] D46052: GNUstep Objective-C ABI version 2

2018-04-26 Thread David Chisnall via Phabricator via cfe-commits
theraven added a comment.

In https://reviews.llvm.org/D46052#1078597, @rjmccall wrote:

> Are you asking for a code review or a design review of the ABI?


I don't think a design review is appropriate here, I am asking for a code 
review.

> The second would be much easier to do from a design document.

If you'd be willing to do a design review, I'd be very happy to send you a copy 
of the ABI document.


Repository:
  rC Clang

https://reviews.llvm.org/D46052



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


[PATCH] D46081: [analyzer] Expand conversion check to check more expressions for overflow and underflow

2018-04-26 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov added a comment.

Looks reasonable. Have you tried on any large codebases? You relax two guards, 
so I would be wary of explosion in false positives.




Comment at: lib/StaticAnalyzer/Checkers/ConversionChecker.cpp:77
 if (Opc == BO_Assign) {
-  LossOfSign = isLossOfSign(Cast, C);
-  LossOfPrecision = isLossOfPrecision(Cast, Cast->getType(), C);
+  if (!B->getRHS()->isIntegerConstantExpr(C.getASTContext())) {
+LossOfSign = isLossOfSign(Cast, C);

Sorry, I don't quite follow: why we don't want to warn when RHS is an integer 
constant?


Repository:
  rC Clang

https://reviews.llvm.org/D46081



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


[PATCH] D41537: Optionally add code completion results for arrow instead of dot

2018-04-26 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan updated this revision to Diff 144076.
yvvan added a comment.

Wrapper around FIxItHint is removed, other review comments are addressed .


https://reviews.llvm.org/D41537

Files:
  include/clang-c/Index.h
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/CodeCompleteConsumer.h
  include/clang/Sema/CodeCompleteOptions.h
  include/clang/Sema/Sema.h
  lib/Frontend/ASTUnit.cpp
  lib/Parse/ParseExpr.cpp
  lib/Sema/CodeCompleteConsumer.cpp
  lib/Sema/SemaCodeComplete.cpp
  test/FixIt/fixit.cpp
  test/Index/complete-arrow-dot.cpp
  test/SemaCXX/member-expr.cpp
  tools/c-index-test/c-index-test.c
  tools/libclang/CIndexCodeCompletion.cpp
  tools/libclang/libclang.exports

Index: tools/libclang/libclang.exports
===
--- tools/libclang/libclang.exports
+++ tools/libclang/libclang.exports
@@ -171,6 +171,10 @@
 clang_getCompletionChunkCompletionString
 clang_getCompletionChunkKind
 clang_getCompletionChunkText
+clang_getCompletionNumCorrections
+clang_getCompletionCorrection
+clang_getCodeCompleteResultsSourceManager
+clang_getCodeCompleteResultsLanguageOptions
 clang_getCompletionNumAnnotations
 clang_getCompletionParent
 clang_getCompletionPriority
Index: tools/libclang/CIndexCodeCompletion.cpp
===
--- tools/libclang/CIndexCodeCompletion.cpp
+++ tools/libclang/CIndexCodeCompletion.cpp
@@ -16,6 +16,7 @@
 #include "CIndexDiagnostic.h"
 #include "CLog.h"
 #include "CXCursor.h"
+#include "CXSourceLocation.h"
 #include "CXString.h"
 #include "CXTranslationUnit.h"
 #include "clang/AST/Decl.h"
@@ -306,6 +307,50 @@
 
 } // end anonymous namespace
 
+unsigned
+clang_getCompletionNumCorrections(CXCompletionString completion_string) {
+  CodeCompletionString *CCStr = (CodeCompletionString *)completion_string;
+
+  if (!CCStr)
+return 0;
+  return static_cast(CCStr->getCorrections().size());
+}
+
+CXString clang_getCompletionCorrection(CXCompletionString completion_string,
+   unsigned correction_index,
+   CXSourceManager source_manager,
+   CXLanguageOptions language_options,
+   CXSourceRange *replacement_range) {
+  CodeCompletionString *CCStr = (CodeCompletionString *)completion_string;
+
+  if (!CCStr) {
+if (replacement_range)
+  *replacement_range = clang_getNullRange();
+return cxstring::createNull();
+  }
+
+  const std::vector &Corrections = CCStr->getCorrections();
+  if (Corrections.size() <= correction_index) {
+if (replacement_range)
+  *replacement_range = clang_getNullRange();
+return cxstring::createNull();
+  }
+
+  const FixItHint &Correction = Corrections[correction_index];
+  if (replacement_range) {
+SourceManager *SourceMgr = (SourceManager *)source_manager;
+LangOptions *LangOpts = (LangOptions *)language_options;
+if (!SourceMgr || !LangOpts) {
+  *replacement_range = clang_getNullRange();
+} else {
+  *replacement_range = cxloc::translateSourceRange(*SourceMgr, *LangOpts,
+   Correction.RemoveRange);
+}
+  }
+
+  return cxstring::createRef(Correction.CodeToInsert.c_str());
+}
+
 /// \brief Tracks the number of code-completion result objects that are 
 /// currently active.
 ///
@@ -532,7 +577,7 @@
 unsigned NumResults) override {
   StoredResults.reserve(StoredResults.size() + NumResults);
   for (unsigned I = 0; I != NumResults; ++I) {
-CodeCompletionString *StoredCompletion
+CodeCompletionString *StoredCompletion
   = Results[I].CreateCodeCompletionString(S, Context, getAllocator(),
   getCodeCompletionTUInfo(),
   includeBriefComments());
@@ -644,6 +689,7 @@
   unsigned options) {
   bool IncludeBriefComments = options & CXCodeComplete_IncludeBriefComments;
   bool SkipPreamble = options & CXCodeComplete_SkipPreamble;
+  bool IncludeCorrections = options & CXCodeComplete_IncludeCorrections;
 
 #ifdef UDP_CODE_COMPLETION_LOGGER
 #ifdef UDP_CODE_COMPLETION_LOGGER_PORT
@@ -650,7 +696,6 @@
   const llvm::TimeRecord &StartTime =  llvm::TimeRecord::getCurrentTime();
 #endif
 #endif
-
   bool EnableLogging = getenv("LIBCLANG_CODE_COMPLETION_LOGGING") != nullptr;
 
   if (cxtu::isNotUsableTU(TU)) {
@@ -691,6 +736,7 @@
   CodeCompleteOptions Opts;
   Opts.IncludeBriefComments = IncludeBriefComments;
   Opts.LoadExternal = !SkipPreamble;
+  Opts.IncludeCorrections = IncludeCorrections;
   CaptureCompletionResults Capture(Opts, *Results, &TU);
 
   // Perform completion.
@@ -797,6 +843,20 @@
   return Results;
 }
 
+CXSourceManager clang_getCodeCompleteResultsSourceManager(CXCodeCompleteResults *results) {
+  AllocatedCXCod

[PATCH] D46108: [ARM] Add __ARM_FEATURE_DOTPROD pre-defined macro

2018-04-26 Thread Oliver Stannard via Phabricator via cfe-commits
olista01 created this revision.
olista01 added reviewers: rengolin, SjoerdMeijer, flyingforyou.
Herald added a reviewer: javed.absar.
Herald added subscribers: llvm-commits, chrib, kristof.beyls.

This adds a pre-defined macro to test if the compiler has support for the 
v8.2-A dot rpoduct intrinsics in AArch32 mode.

  

The AAcrh64 equivalent has already been added by 
https://reviews.llvm.org/rL330229.

  

The ACLE spec which describes this macro hasn't been published yet, but this is 
based on the final internal draft, and GCC has already implemented this.


Repository:
  rL LLVM

https://reviews.llvm.org/D46108

Files:
  lib/Basic/Targets/ARM.cpp
  lib/Basic/Targets/ARM.h
  test/Preprocessor/arm-target-features.c


Index: test/Preprocessor/arm-target-features.c
===
--- test/Preprocessor/arm-target-features.c
+++ test/Preprocessor/arm-target-features.c
@@ -6,6 +6,7 @@
 // CHECK-V8A: #define __ARM_FEATURE_DIRECTED_ROUNDING 1
 // CHECK-V8A: #define __ARM_FEATURE_NUMERIC_MAXMIN 1
 // CHECK-V8A-NOT: #define __ARM_FP 0x
+// CHECK-V8A-NOT: #define __ARM_FEATURE_DOTPROD
 
 // RUN: %clang -target armv8a-none-linux-gnueabi -x c -E -dM %s -o - | 
FileCheck -match-full-lines --check-prefix=CHECK-V8A-ALLOW-FP-INSTR %s
 // RUN: %clang -target armv8a-none-linux-gnueabihf -x c -E -dM %s -o - | 
FileCheck -match-full-lines --check-prefix=CHECK-V8A-ALLOW-FP-INSTR %s
@@ -18,6 +19,7 @@
 // CHECK-V8A-ALLOW-FP-INSTR: #define __ARM_FP 0xe
 // CHECK-V8A-ALLOW-FP-INSTR: #define __ARM_FP16_ARGS 1
 // CHECK-V8A-ALLOW-FP-INSTR: #define __ARM_FP16_FORMAT_IEEE 1
+// CHECK-V8A-ALLOW-FP-INSTR-V8A-NOT: #define __ARM_FEATURE_DOTPROD
 
 // RUN: %clang -target arm-none-linux-gnueabi -march=armv8.2a+fp16 -x c -E -dM 
%s -o - | FileCheck -match-full-lines 
--check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s
 // CHECK-FULLFP16-VECTOR-SCALAR: #define __ARM_FEATURE_FP16_SCALAR_ARITHMETIC 1
@@ -30,6 +32,9 @@
 // CHECK-FULLFP16-SCALAR-NOT:   #define __ARM_FEATURE_FP16_VECTOR_ARITHMETIC 1
 // CHECK-FULLFP16-SCALAR:   #define __ARM_FP 0xe
 // CHECK-FULLFP16-SCALAR:   #define __ARM_FP16_FORMAT_IEEE 1
+//
+// RUN: %clang -target arm-none-linux-gnueabi -march=armv8.2a+dotprod -x c -E 
-dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-DOTPROD %s
+// CHECK-DOTPROD: #define __ARM_FEATURE_DOTPROD 1
 
 // RUN: %clang -target armv8r-none-linux-gnu -x c -E -dM %s -o - | FileCheck 
-match-full-lines --check-prefix=CHECK-V8R %s
 // CHECK-V8R: #define __ARMEL__ 1
Index: lib/Basic/Targets/ARM.h
===
--- lib/Basic/Targets/ARM.h
+++ lib/Basic/Targets/ARM.h
@@ -69,6 +69,7 @@
   unsigned Crypto : 1;
   unsigned DSP : 1;
   unsigned Unaligned : 1;
+  unsigned DotProd : 1;
 
   enum {
 LDREX_B = (1 << 0), /// byte (8-bit)
Index: lib/Basic/Targets/ARM.cpp
===
--- lib/Basic/Targets/ARM.cpp
+++ lib/Basic/Targets/ARM.cpp
@@ -390,6 +390,7 @@
   Unaligned = 1;
   SoftFloat = SoftFloatABI = false;
   HWDiv = 0;
+  DotProd = 0;
 
   // This does not diagnose illegal cases like having both
   // "+vfpv2" and "+vfpv3" or having "+neon" and "+fp-only-sp".
@@ -432,6 +433,8 @@
   HW_FP |= HW_FP_HP;
 } else if (Feature == "+fullfp16") {
   HasLegalHalfType = true;
+} else if (Feature == "+dotprod") {
+  DotProd = true;
 }
   }
   HW_FP &= ~HW_FP_remove;
@@ -731,6 +734,8 @@
   if (HasLegalHalfType)
 Builder.defineMacro("__ARM_FEATURE_FP16_SCALAR_ARITHMETIC", "1");
 
+  if (DotProd)
+Builder.defineMacro("__ARM_FEATURE_DOTPROD", "1");
 
   switch (ArchKind) {
   default:


Index: test/Preprocessor/arm-target-features.c
===
--- test/Preprocessor/arm-target-features.c
+++ test/Preprocessor/arm-target-features.c
@@ -6,6 +6,7 @@
 // CHECK-V8A: #define __ARM_FEATURE_DIRECTED_ROUNDING 1
 // CHECK-V8A: #define __ARM_FEATURE_NUMERIC_MAXMIN 1
 // CHECK-V8A-NOT: #define __ARM_FP 0x
+// CHECK-V8A-NOT: #define __ARM_FEATURE_DOTPROD
 
 // RUN: %clang -target armv8a-none-linux-gnueabi -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V8A-ALLOW-FP-INSTR %s
 // RUN: %clang -target armv8a-none-linux-gnueabihf -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V8A-ALLOW-FP-INSTR %s
@@ -18,6 +19,7 @@
 // CHECK-V8A-ALLOW-FP-INSTR: #define __ARM_FP 0xe
 // CHECK-V8A-ALLOW-FP-INSTR: #define __ARM_FP16_ARGS 1
 // CHECK-V8A-ALLOW-FP-INSTR: #define __ARM_FP16_FORMAT_IEEE 1
+// CHECK-V8A-ALLOW-FP-INSTR-V8A-NOT: #define __ARM_FEATURE_DOTPROD
 
 // RUN: %clang -target arm-none-linux-gnueabi -march=armv8.2a+fp16 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s
 // CHECK-FULLFP16-VECTOR-SCALAR: #define __ARM_FEATURE_FP16_SCALAR_ARITHMETIC 1
@@ -30,6 +32,9 @@
 // CHECK-FULLFP16-SCALAR-NOT:   #define __ARM_FEATURE_F

[PATCH] D46000: [AST] Added a helper to extract a user-friendly text of a comment.

2018-04-26 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 144083.
ilya-biryukov marked 2 inline comments as done.
ilya-biryukov added a comment.

- Remove tryLexCommands(), call into helper that parses commands directly
- Addressed other review comments


Repository:
  rC Clang

https://reviews.llvm.org/D46000

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

Index: lib/AST/RawCommentList.cpp
===
--- lib/AST/RawCommentList.cpp
+++ lib/AST/RawCommentList.cpp
@@ -335,3 +335,90 @@
  BeforeThanCompare(SourceMgr));
   std::swap(Comments, MergedComments);
 }
+
+std::string RawComment::getFormattedText(const ASTContext &Ctx) const {
+  auto &SourceMgr = Ctx.getSourceManager();
+  llvm::StringRef CommentText = getRawText(SourceMgr);
+  if (CommentText.empty())
+return "";
+
+  llvm::BumpPtrAllocator Allocator;
+  comments::Lexer L(Allocator, Ctx.getDiagnostics(),
+Ctx.getCommentCommandTraits(), getSourceRange().getBegin(),
+CommentText.begin(), CommentText.end(),
+/*ParseCommands=*/false);
+
+  std::string Result;
+  // A column number of the first non-whitespace token in the comment text.
+  // We skip whitespace up to this column, but keep the whitespace after this
+  // column. IndentColumn is calculated when lexing the first line and reused
+  // for the rest of lines.
+  unsigned IndentColumn = 0;
+
+  // Processes one line of the comment and adds it to the result.
+  // Handles skipping the indent at the start of the line.
+  // Returns false when eof is reached and true otherwise.
+  auto LexLine = [&](bool IsFirstLine) -> bool {
+comments::Token Tok;
+// Lex the first token on the line. We handle it separately, because we to
+// fix up its indentation.
+L.lex(Tok);
+if (Tok.is(comments::tok::eof))
+  return false;
+if (Tok.is(comments::tok::newline)) {
+  Result += "\n";
+  return true;
+}
+llvm::StringRef TokText = L.getSpelling(Tok, SourceMgr);
+bool LocInvalid = false;
+unsigned TokColumn =
+SourceMgr.getSpellingColumnNumber(Tok.getLocation(), &LocInvalid);
+if (LocInvalid)
+  TokColumn = 0;
+// Amount of leading whitespace in TokText.
+size_t WhitespaceLen = TokText.find_first_not_of(" \t");
+if (WhitespaceLen == StringRef::npos)
+  WhitespaceLen = TokText.size();
+// Remember the amount of whitespace we skipped in the first line to remove
+// indent up to that column in the following lines.
+if (IsFirstLine)
+  IndentColumn = TokColumn + WhitespaceLen;
+
+// Amount of leading whitespace we actually want to skip.
+// For the first line we skip all the whitespace.
+// For the rest of the lines, we skip whitespace up to IndentColumn.
+unsigned SkipLen =
+LocInvalid || IsFirstLine
+? WhitespaceLen
+: std::min(WhitespaceLen,
+   (size_t)std::max((int)IndentColumn - (int)TokColumn, 0));
+llvm::StringRef Trimmed = TokText.drop_front(SkipLen);
+Result += Trimmed;
+// Lex all tokens in the rest of the line.
+for (L.lex(Tok); Tok.isNot(comments::tok::eof); L.lex(Tok)) {
+  if (Tok.is(comments::tok::newline)) {
+Result += "\n";
+return true;
+  }
+  Result += L.getSpelling(Tok, SourceMgr);
+}
+// We've reached the end of the line.
+return false;
+  };
+
+  auto DropTrailingNewLines = [](std::string &Str) {
+while (Str.back() == '\n')
+  Str.pop_back();
+  };
+
+  // Proces first line separately to remember indent for the following lines.
+  if (!LexLine(/*IsFirstLine=*/true)) {
+DropTrailingNewLines(Result);
+return Result;
+  }
+  // Process the rest of the lines.
+  while (LexLine(/*IsFirstLine=*/false))
+;
+  DropTrailingNewLines(Result);
+  return Result;
+}
Index: lib/AST/CommentLexer.cpp
===
--- lib/AST/CommentLexer.cpp
+++ lib/AST/CommentLexer.cpp
@@ -294,6 +294,38 @@
   assert(CommentState == LCS_InsideBCPLComment ||
  CommentState == LCS_InsideCComment);
 
+  // Handles lexing non-command text, i.e. text and newline.
+  auto HandleNonCommandToken = [&]() -> void {
+assert(State == LS_Normal);
+
+const char *TokenPtr = BufferPtr;
+assert(TokenPtr < CommentEnd);
+switch (*TokenPtr) {
+  case '\n':
+  case '\r':
+  TokenPtr = skipNewline(TokenPtr, CommentEnd);
+  formTokenWithChars(T, TokenPtr, tok::newline);
+
+  if (CommentState == LCS_InsideCComment)
+skipLineStartingDecorations();
+  return;
+
+  default: {
+  size_t End =
+  StringRef(TokenPtr, CommentEnd - TokenPtr).find_first_of("\n\r\\@&<");
+  if (End != StringRef::npos)
+TokenPtr += End;
+  else
+T

[PATCH] D46109: [ARM, AArch64] Add intrinsics for dot product instructions

2018-04-26 Thread Oliver Stannard via Phabricator via cfe-commits
olista01 created this revision.
olista01 added reviewers: rengolin, SjoerdMeijer, flyingforyou.
Herald added a reviewer: javed.absar.
Herald added subscribers: llvm-commits, chrib, kristof.beyls.

The ACLE spec which describes these intrinsics hasn't been published yet, but 
this is based on the final draft which will be published soon, and these have 
already been implemented by GCC.


Repository:
  rL LLVM

https://reviews.llvm.org/D46109

Files:
  include/clang/Basic/arm_neon.td
  include/clang/Basic/arm_neon_incl.td
  lib/CodeGen/CGBuiltin.cpp
  test/CodeGen/aarch64-neon-dot-product.c
  test/CodeGen/arm-neon-dot-product.c
  utils/TableGen/NeonEmitter.cpp

Index: utils/TableGen/NeonEmitter.cpp
===
--- utils/TableGen/NeonEmitter.cpp
+++ utils/TableGen/NeonEmitter.cpp
@@ -995,6 +995,19 @@
 if (!AppliedQuad)
   Bitwidth *= 2;
 break;
+  case '7':
+if (AppliedQuad)
+  Bitwidth /= 2;
+ElementBitwidth = 8;
+break;
+  case '8':
+ElementBitwidth = 8;
+break;
+  case '9':
+if (!AppliedQuad)
+  Bitwidth *= 2;
+ElementBitwidth = 8;
+break;
   default:
 llvm_unreachable("Unhandled character!");
   }
Index: test/CodeGen/arm-neon-dot-product.c
===
--- /dev/null
+++ test/CodeGen/arm-neon-dot-product.c
@@ -0,0 +1,76 @@
+// RUN: %clang_cc1 -triple armv8-linux-gnueabihf -target-cpu cortex-a57 -target-feature +dotprod \
+// RUN: -disable-O0-optnone  -emit-llvm -o - %s | opt -S -instcombine | FileCheck %s
+
+// REQUIRES: arm-registered-target
+
+// Test ARM v8.2-A dot product intrinsics
+
+#include 
+
+uint32x2_t test_vdot_u32(uint32x2_t a, uint8x8_t b, uint8x8_t c) {
+// CHECK-LABEL: define <2 x i32> @test_vdot_u32(<2 x i32> %a, <8 x i8> %b, <8 x i8> %c)
+// CHECK: [[RESULT:%.*]] = call <2 x i32> @llvm.arm.neon.udot.v2i32.v8i8(<2 x i32> %a, <8 x i8> %b, <8 x i8> %c)
+// CHECK: ret <2 x i32> [[RESULT]]
+  return vdot_u32(a, b, c);
+}
+
+uint32x4_t test_vdotq_u32(uint32x4_t a, uint8x16_t b, uint8x16_t c) {
+// CHECK-LABEL: define <4 x i32> @test_vdotq_u32(<4 x i32> %a, <16 x i8> %b, <16 x i8> %c)
+// CHECK: [[RESULT:%.*]] = call <4 x i32> @llvm.arm.neon.udot.v4i32.v16i8(<4 x i32> %a, <16 x i8> %b, <16 x i8> %c)
+// CHECK: ret <4 x i32> [[RESULT]]
+  return vdotq_u32(a, b, c);
+}
+
+int32x2_t test_vdot_s32(int32x2_t a, int8x8_t b, int8x8_t c) {
+// CHECK-LABEL: define <2 x i32> @test_vdot_s32(<2 x i32> %a, <8 x i8> %b, <8 x i8> %c)
+// CHECK: [[RESULT:%.*]] = call <2 x i32> @llvm.arm.neon.sdot.v2i32.v8i8(<2 x i32> %a, <8 x i8> %b, <8 x i8> %c)
+// CHECK: ret <2 x i32> [[RESULT]]
+  return vdot_s32(a, b, c);
+}
+
+int32x4_t test_vdotq_s32(int32x4_t a, int8x16_t b, int8x16_t c) {
+// CHECK-LABEL: define <4 x i32> @test_vdotq_s32(<4 x i32> %a, <16 x i8> %b, <16 x i8> %c)
+// CHECK: [[RESULT:%.*]] = call <4 x i32> @llvm.arm.neon.sdot.v4i32.v16i8(<4 x i32> %a, <16 x i8> %b, <16 x i8> %c)
+// CHECK: ret <4 x i32> [[RESULT]]
+  return vdotq_s32(a, b, c);
+}
+
+uint32x2_t test_vdot_lane_u32(uint32x2_t a, uint8x8_t b, uint8x8_t c) {
+// CHECK-LABEL: define <2 x i32> @test_vdot_lane_u32(<2 x i32> %a, <8 x i8> %b, <8 x i8> %c)
+// CHECK: [[CAST1:%.*]] = bitcast <8 x i8> %c to <2 x i32>
+// CHECK: [[SHUFFLE:%.*]] = shufflevector <2 x i32> [[CAST1]], <2 x i32> undef, <2 x i32> 
+// CHECK: [[CAST2:%.*]] = bitcast <2 x i32> [[SHUFFLE]] to <8 x i8>
+// CHECK: [[RESULT:%.*]] = call <2 x i32> @llvm.arm.neon.udot.v2i32.v8i8(<2 x i32> %a, <8 x i8> %b, <8 x i8> [[CAST2]])
+// CHECK: ret <2 x i32> [[RESULT]]
+  return vdot_lane_u32(a, b, c, 1);
+}
+
+uint32x4_t test_vdotq_lane_u32(uint32x4_t a, uint8x16_t b, uint8x8_t c) {
+// CHECK-LABEL: define <4 x i32> @test_vdotq_lane_u32(<4 x i32> %a, <16 x i8> %b, <8 x i8> %c)
+// CHECK: [[CAST1:%.*]] = bitcast <8 x i8> %c to <2 x i32>
+// CHECK: [[SHUFFLE:%.*]] = shufflevector <2 x i32> [[CAST1]], <2 x i32> undef, <4 x i32> 
+// CHECK: [[CAST2:%.*]] = bitcast <4 x i32> [[SHUFFLE]] to <16 x i8>
+// CHECK: [[RESULT:%.*]] = call <4 x i32> @llvm.arm.neon.udot.v4i32.v16i8(<4 x i32> %a, <16 x i8> %b, <16 x i8> [[CAST2]])
+// CHECK: ret <4 x i32> [[RESULT]]
+  return vdotq_lane_u32(a, b, c, 1);
+}
+
+int32x2_t test_vdot_lane_s32(int32x2_t a, int8x8_t b, int8x8_t c) {
+// CHECK-LABEL: define <2 x i32> @test_vdot_lane_s32(<2 x i32> %a, <8 x i8> %b, <8 x i8> %c)
+// CHECK: [[CAST1:%.*]] = bitcast <8 x i8> %c to <2 x i32>
+// CHECK: [[SHUFFLE:%.*]] = shufflevector <2 x i32> [[CAST1]], <2 x i32> undef, <2 x i32> 
+// CHECK: [[CAST2:%.*]] = bitcast <2 x i32> [[SHUFFLE]] to <8 x i8>
+// CHECK: [[RESULT:%.*]] = call <2 x i32> @llvm.arm.neon.sdot.v2i32.v8i8(<2 x i32> %a, <8 x i8> %b, <8 x i8> [[CAST2]])
+// CHECK: ret <2 x i32> [[RESULT]]
+  return vdot_lane_s32(a, b, c, 1);
+}
+
+int32x4_t test_vdotq_lane_s32(int32x4_t a, int8x16_t b, int8x8_t c) {
+// CHECK-LABEL: define <4 x i32> @test_vdotq_lane_s32(<4 x i32> %a, <16 x i8> %b, <8 x i8> 

[PATCH] D46000: [AST] Added a helper to extract a user-friendly text of a comment.

2018-04-26 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov marked 4 inline comments as done.
ilya-biryukov added inline comments.



Comment at: include/clang/AST/RawCommentList.h:118
+  /// //   Parts of it  might be indented.
+  /// /* The comments styles might be mixed. */
+  ///  into

ioeric wrote:
> I'm trying to understand how these cases and RawComment work.
> 
> For this case, are the `// ... ` block and `/* ... */` merged in one 
> `RawComment` by default?
Yes, `RawComment` can represent multiple merged comments of different styles.



Comment at: include/clang/AST/RawCommentList.h:126
+  ///  *   This is a second line. It is indented.
+  ///  * This is a third line. */
+  /// and

ioeric wrote:
> Are the `*`s in each lines automatically consumed by the lexer?
Yes, see `comments::Lexer::skipLineStartingDecorations()`



Comment at: lib/AST/RawCommentList.cpp:380
+SourceMgr.getSpellingColumnNumber(Tok.getLocation(), &LocInvalid);
+if (LocInvalid)
+  TokColumn = 0;

ioeric wrote:
> ilya-biryukov wrote:
> > ilya-biryukov wrote:
> > > ioeric wrote:
> > > > Explain when this would be invalid and why `TokColumn = 0` is used?
> > > I don't know whether this can be even be invalid, but I'm not confident 
> > > enough to add an assert there.
> > > `TokColumn = 0` seems like a reasonable way to recover if we can't 
> > > compute the column number, i.e. assume the line starts at the first 
> > > column if SourceLocation of the line was invalid for any reason.
> > > 
> > > This whole column thing looks weird to me, maybe I should just remove it 
> > > altogether and just remove the same amount of whitespace in all the 
> > > lines. WDYT?
> > On a second thought, now I remember why I added this in the first place.
> > To support the following example we want to take column numbers into 
> > account:
> > 
> > ```
> > class Foo {
> > /* A block comment
> >spanning multiple lines
> >has too many spaces on the all lines except the first one.
> > */
> > int func();
> > };
> > ```
> So I think you would want to force `MaxSkip` to 0 if token loc is invalid to 
> make sure no comment is accidentally eaten?
Makes sense, thanks. Unfortunately I don't have any ideas on how we can test 
this case :-(



Comment at: lib/AST/RawCommentList.cpp:343
+  if (CommentText.empty())
+return ""; // we couldn't retreive the comment.
+

ioeric wrote:
> nit: We don't really know if there was a failure or the comment is simply 
> empty. So I'd probably leave out the comment here to avoid confusion.
`getRawTextSlow` returns empty string on error, so this comment has some ground.
Removed it anyway



Comment at: lib/AST/RawCommentList.cpp:349
+CommentText.begin(), CommentText.end(),
+/*ParseCommentText=*/false);
+

ioeric wrote:
> `s/ParseCommentText/ParseCommands/`?
Thanks for catching this!



Comment at: lib/AST/RawCommentList.cpp:393
+
+llvm::StringRef Trimmed = TokText.drop_front(std::min(MaxSkip, 
WhitespaceLen));
+Result += Trimmed;

ioeric wrote:
> I think `MaxSkip` could be removed with:
> 
> ```
> llvm::StringRef Trimmed = TokText.drop_front(IsFirstLine ? WhitespaceLen : 
>  std::max((int)IndentColumn - 
> (int)TokColumn, 0)));
> ```
I've removed `MaxSkip`, but introduced `SkipLen` instead that captures an 
actual numbers of chars we want to skip.
I would still keep as a separate variable, as the expression seems somewhat 
complex and giving a name to it, arguably, makes the code more readable.


Repository:
  rC Clang

https://reviews.llvm.org/D46000



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


[PATCH] D46050: [Frontend] Avoid running plugins during code completion parse

2018-04-26 Thread Nikolai Kosjar via Phabricator via cfe-commits
nik added a comment.

In https://reviews.llvm.org/D46050#1078112, @thakis wrote:

> Seems reasonable; can you add a test for this (maybe somewhere in 
> clang/test/Frontend/plugin*)?


Done.

In https://reviews.llvm.org/D46050#1078155, @john.brawn wrote:

> I know very little about how code completion works, but it's not immediately 
> obvious to me that disabling plugin ast consumers when code completion is 
> enabled is necessarily correct. In what kind of scenario would we both have a 
> plugin loaded that wants to insert an ast consumer before/after the main one, 
> and also be doing code completion?


For example if you use libclang with the clang tidy plugin. I've put this into 
the commit message.


Repository:
  rC Clang

https://reviews.llvm.org/D46050



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


[PATCH] D46050: [Frontend] Avoid running plugins during code completion parse

2018-04-26 Thread Nikolai Kosjar via Phabricator via cfe-commits
nik updated this revision to Diff 144084.
nik added a comment.

Added a test and clarified scenario in commit message.


Repository:
  rC Clang

https://reviews.llvm.org/D46050

Files:
  lib/Frontend/FrontendAction.cpp
  test/Frontend/plugins.c


Index: test/Frontend/plugins.c
===
--- test/Frontend/plugins.c
+++ test/Frontend/plugins.c
@@ -3,3 +3,9 @@
 
 // CHECK: top-level-decl: "x"
 void x();
+
+// RUN: c-index-test -code-completion-at=%s:6:1 -load 
%llvmshlibdir/PrintFunctionNames%pluginext -add-plugin print-fns %s | FileCheck 
-check-prefix=CHECK-COMPLETION-WITHOUT-PLUGINS  %s
+// REQUIRES: plugins, examples
+
+// CHECK-COMPLETION-WITHOUT-PLUGINS: macro definition:{{.*}}
+// CHECK-COMPLETION-WITHOUT-PLUGINS-NOT: top-level-decl: "x"
Index: lib/Frontend/FrontendAction.cpp
===
--- lib/Frontend/FrontendAction.cpp
+++ lib/Frontend/FrontendAction.cpp
@@ -153,6 +153,10 @@
   if (FrontendPluginRegistry::begin() == FrontendPluginRegistry::end())
 return Consumer;
 
+  // If this is a code completion run, avoid invoking the plugin consumers
+  if (CI.hasCodeCompletionConsumer())
+return Consumer;
+
   // Collect the list of plugins that go before the main action (in Consumers)
   // or after it (in AfterConsumers)
   std::vector> Consumers;


Index: test/Frontend/plugins.c
===
--- test/Frontend/plugins.c
+++ test/Frontend/plugins.c
@@ -3,3 +3,9 @@
 
 // CHECK: top-level-decl: "x"
 void x();
+
+// RUN: c-index-test -code-completion-at=%s:6:1 -load %llvmshlibdir/PrintFunctionNames%pluginext -add-plugin print-fns %s | FileCheck -check-prefix=CHECK-COMPLETION-WITHOUT-PLUGINS  %s
+// REQUIRES: plugins, examples
+
+// CHECK-COMPLETION-WITHOUT-PLUGINS: macro definition:{{.*}}
+// CHECK-COMPLETION-WITHOUT-PLUGINS-NOT: top-level-decl: "x"
Index: lib/Frontend/FrontendAction.cpp
===
--- lib/Frontend/FrontendAction.cpp
+++ lib/Frontend/FrontendAction.cpp
@@ -153,6 +153,10 @@
   if (FrontendPluginRegistry::begin() == FrontendPluginRegistry::end())
 return Consumer;
 
+  // If this is a code completion run, avoid invoking the plugin consumers
+  if (CI.hasCodeCompletionConsumer())
+return Consumer;
+
   // Collect the list of plugins that go before the main action (in Consumers)
   // or after it (in AfterConsumers)
   std::vector> Consumers;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46081: [analyzer] Expand conversion check to check more expressions for overflow and underflow

2018-04-26 Thread Whisperity via Phabricator via cfe-commits
whisperity added a comment.

While I understand extending the analyzer to cover more is a good approach, 
there is `-Wconversion` which seemingly covers this -- or at least the trivial 
case(?):

  #include 
  #include 
  
  void foo(unsigned x)
  {
printf("%u\n", x);
  }
  
  int main()
  {
int i = -1;
foo(i);
  
std::vector x;
x[i] = 5;
  }



  $ clang++ -Wconversion -o/dev/null check.cpp 
  check.cpp:12:7: warning: implicit conversion changes signedness: 'int' to 
'unsigned int' [-Wsign-conversion]
foo(i);
~~~ ^
  check.cpp:15:5: warning: implicit conversion changes signedness: 'int' to 
'std::vector::size_type' (aka 'unsigned long') [-Wsign-conversion]
x[i] = 5;
~ ^


Repository:
  rC Clang

https://reviews.llvm.org/D46081



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


[PATCH] D46050: [Frontend] Avoid running plugins during code completion parse

2018-04-26 Thread Nikolai Kosjar via Phabricator via cfe-commits
nik added inline comments.



Comment at: test/Frontend/plugins.c:7
+
+// RUN: c-index-test -code-completion-at=%s:6:1 -load 
%llvmshlibdir/PrintFunctionNames%pluginext -add-plugin print-fns %s | FileCheck 
-check-prefix=CHECK-COMPLETION-WITHOUT-PLUGINS  %s
+// REQUIRES: plugins, examples

Should this test rather go into test/Index because of the c-index-test?



Comment at: test/Frontend/plugins.c:8
+// RUN: c-index-test -code-completion-at=%s:6:1 -load 
%llvmshlibdir/PrintFunctionNames%pluginext -add-plugin print-fns %s | FileCheck 
-check-prefix=CHECK-COMPLETION-WITHOUT-PLUGINS  %s
+// REQUIRES: plugins, examples
+

Note that I actually have problems with this REQUIRES line. I use 
-DCLANG_BUILD_EXAMPLES and -DDBUILD_SHARED_LIBS=ON and this test (and the one 
above too) is skipped/unsupported. What else do I need?

Note that If I remove this line, the test is run - apparently the requirements 
are fulfilled, but not properly detected. I guess this is set up issue on my 
local machine?


Repository:
  rC Clang

https://reviews.llvm.org/D46050



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


[PATCH] D41537: Optionally add code completion results for arrow instead of dot

2018-04-26 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

Could you upload the patch with full context?




Comment at: include/clang/Sema/CodeCompleteConsumer.h:704
+CXAvailabilityKind Availability,
+const std::vector &Corrections)
   : Allocator(Allocator), CCTUInfo(CCTUInfo), Priority(Priority),

yvvan wrote:
> ilya-biryukov wrote:
> > Maybe accept the vector by value instead of const reference to allow the 
> > clients to `std::move` the argument and avoid copies?
> but if it's accepted by value - it's one copy already by default
> 
> Instead I can add one more constructor with rvalue reference.
If it's accepted by value, it's copy by default for l-values, but callers have 
an option to `std::move` explicitly.
Having an r-value ref overload prevents from calling with l-values (e.g. local 
variables), i.e. requires either an explicitly copy to a temporary or 
`std::move`.

In general, I would still suggest passing by-value, unless it's particularly 
important to prohibit extra copies (e.g. for performance reasons, but I don't 
think it's the case here).



Comment at: include/clang/Sema/CodeCompleteConsumer.h:600
+  /// \brief Check if this completion requires some correction.
+  const std::vector &getCorrections() const { return Corrections; }
+

NIT: return `llvm::ArrayRef` instead. 



Comment at: include/clang/Sema/CodeCompleteConsumer.h:1040
 
+  /// \brief Whether to try dot to arrow correction if arrow operator can be 
applied.
+  bool includeCorrections() const {

Mention other corrections are possible in this comment too?



Comment at: include/clang/Sema/CodeCompleteOptions.h:43
+  /// Show also results after dot to arrow correction if arrow operator can be 
applied.
+  unsigned IncludeCorrections : 1;
+

Mention other corrections are possible in this comment too?




https://reviews.llvm.org/D41537



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


[PATCH] D46112: Allow _Atomic to be specified on incomplete types

2018-04-26 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman created this revision.
aaron.ballman added a reviewer: rsmith.

The C standard does not prohibit the _Atomic specifier on incomplete types, 
which turns out to be sometimes useful.

This addresses PR37237.

Note that C++ still requires checking if the type is complete in order to 
support member pointers under the Microsoft ABI (because that check completes 
some information on the type), which is a use case we have in 
test\SemaCXX\atomic-type.cpp.


https://reviews.llvm.org/D46112

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaType.cpp
  test/Sema/atomic-type.c


Index: test/Sema/atomic-type.c
===
--- test/Sema/atomic-type.c
+++ test/Sema/atomic-type.c
@@ -16,7 +16,10 @@
 extern _Atomic(int (*)(int(*)[10], int(*)[10])) mergetest;
 
 _Atomic(int()) error1; // expected-error {{_Atomic cannot be applied to 
function type}}
-_Atomic(struct ErrorS) error2; // expected-error {{_Atomic cannot be applied 
to incomplete type}} expected-note {{forward declaration}}
+_Atomic(struct ErrorS) error2;
 _Atomic(int[10]) error3; // expected-error {{_Atomic cannot be applied to 
array type}}
 _Atomic(const int) error4; // expected-error {{_Atomic cannot be applied to 
qualified type}}
 _Atomic(_Atomic(int)) error5; // expected-error {{_Atomic cannot be applied to 
atomic type}}
+
+void g(_Atomic void *ptr);
+void h(_Atomic struct Incomplete *ptr); // expected-warning {{declaration of 
'struct Incomplete' will not be visible outside of this function}}
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -8007,25 +8007,21 @@
 
 QualType Sema::BuildAtomicType(QualType T, SourceLocation Loc) {
   if (!T->isDependentType()) {
-// FIXME: It isn't entirely clear whether incomplete atomic types
-// are allowed or not; for simplicity, ban them for the moment.
-if (RequireCompleteType(Loc, T, diag::err_atomic_specifier_bad_type, 0))
-  return QualType();
-
 int DisallowedKind = -1;
 if (T->isArrayType())
-  DisallowedKind = 1;
+  DisallowedKind = 0;
 else if (T->isFunctionType())
-  DisallowedKind = 2;
+  DisallowedKind = 1;
 else if (T->isReferenceType())
-  DisallowedKind = 3;
+  DisallowedKind = 2;
 else if (T->isAtomicType())
-  DisallowedKind = 4;
+  DisallowedKind = 3;
 else if (T.hasQualifiers())
-  DisallowedKind = 5;
-else if (!T.isTriviallyCopyableType(Context))
+  DisallowedKind = 4;
+else if (LangOpts.CPlusPlus && isCompleteType(Loc, T) &&
+ !T.isTriviallyCopyableType(Context))
   // Some other non-trivially-copyable type (probably a C++ class)
-  DisallowedKind = 6;
+  DisallowedKind = 5;
 
 if (DisallowedKind != -1) {
   Diag(Loc, diag::err_atomic_specifier_bad_type) << DisallowedKind << T;
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -5504,7 +5504,7 @@
   "incomplete result type %0 in function definition">;
 def err_atomic_specifier_bad_type : Error<
   "_Atomic cannot be applied to "
-  "%select{incomplete |array |function |reference |atomic |qualified |}0type "
+  "%select{array |function |reference |atomic |qualified |}0type "
   "%1 %select{||which is not trivially copyable}0">;
 
 // Expressions.


Index: test/Sema/atomic-type.c
===
--- test/Sema/atomic-type.c
+++ test/Sema/atomic-type.c
@@ -16,7 +16,10 @@
 extern _Atomic(int (*)(int(*)[10], int(*)[10])) mergetest;
 
 _Atomic(int()) error1; // expected-error {{_Atomic cannot be applied to function type}}
-_Atomic(struct ErrorS) error2; // expected-error {{_Atomic cannot be applied to incomplete type}} expected-note {{forward declaration}}
+_Atomic(struct ErrorS) error2;
 _Atomic(int[10]) error3; // expected-error {{_Atomic cannot be applied to array type}}
 _Atomic(const int) error4; // expected-error {{_Atomic cannot be applied to qualified type}}
 _Atomic(_Atomic(int)) error5; // expected-error {{_Atomic cannot be applied to atomic type}}
+
+void g(_Atomic void *ptr);
+void h(_Atomic struct Incomplete *ptr); // expected-warning {{declaration of 'struct Incomplete' will not be visible outside of this function}}
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -8007,25 +8007,21 @@
 
 QualType Sema::BuildAtomicType(QualType T, SourceLocation Loc) {
   if (!T->isDependentType()) {
-// FIXME: It isn't entirely clear whether incomplete atomic types
-// are allowed or not; for simplicity, ban them for the moment.
-if (RequireCompleteType(Loc, T, diag::err_atomic_specifier_bad_type, 0))
-  return QualType(

[PATCH] D45815: [libclang] Add options to limit skipping of function bodies

2018-04-26 Thread Erik Verbruggen via Phabricator via cfe-commits
erikjv added a comment.

About the timing testing: I'm not very familiar with boost, but it probably has 
a library that's using templates more than either LLVM or Qt. Maybe you can 
test one of those too?

LGTM otherwise.


Repository:
  rC Clang

https://reviews.llvm.org/D45815



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


[PATCH] D44684: [mips] Improve handling of -fno-[pic/PIC] option

2018-04-26 Thread Aleksandar Beserminji via Phabricator via cfe-commits
abeserminji updated this revision to Diff 144092.
abeserminji added a comment.

Comments resolved.


Repository:
  rL LLVM

https://reviews.llvm.org/D44684

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  lib/Driver/ToolChains/Arch/Mips.cpp
  lib/Driver/ToolChains/CommonArgs.cpp
  test/Driver/mips-abicalls-error.c
  test/Driver/mips-abicalls-warning.c
  test/Driver/mips-as.c
  test/Driver/mips-features.c

Index: test/Driver/mips-features.c
===
--- test/Driver/mips-features.c
+++ test/Driver/mips-features.c
@@ -11,7 +11,7 @@
 // CHECK-MNOABICALLS: "-target-feature" "+noabicalls"
 //
 // -mno-abicalls non-PIC N64
-// RUN: %clang -target mips64-linux-gnu -### -c -fno-PIC %s 2>&1 \
+// RUN: %clang -target mips64-linux-gnu -### -c -fno-PIC -mno-abicalls %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-MNOABICALLS-N64NPIC %s
 // CHECK-MNOABICALLS-N64NPIC: "-target-feature" "+noabicalls"
 //
@@ -86,13 +86,13 @@
 // CHECK-MEMBEDDEDDATADEF-NOT: "-mllvm" "-membedded-data"
 //
 // MIPS64 + N64: -fno-pic -> -mno-abicalls -mgpopt
-// RUN: %clang -target mips64-mti-elf -mabi=64 -### -c %s -fno-pic 2>&1 \
+// RUN: %clang -target mips64-mti-elf -mabi=64 -### -c %s -fno-pic -mno-abicalls 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-N64-GPOPT %s
 // CHECK-N64-GPOPT: "-target-feature" "+noabicalls"
 // CHECK-N64-GPOPT: "-mllvm" "-mgpopt"
 //
 // MIPS64 + N64: -fno-pic -mno-gpopt
-// RUN: %clang -target mips64-mti-elf -mabi=64 -### -c %s -fno-pic -mno-gpopt 2>&1 \
+// RUN: %clang -target mips64-mti-elf -mabi=64 -### -c %s -fno-pic -mno-abicalls -mno-gpopt 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-N64-MNO-GPOPT %s
 // CHECK-N64-MNO-GPOPT: "-target-feature" "+noabicalls"
 // CHECK-N64-MNO-GPOPT-NOT: "-mllvm" "-mgpopt"
Index: test/Driver/mips-as.c
===
--- test/Driver/mips-as.c
+++ test/Driver/mips-as.c
@@ -21,7 +21,7 @@
 // MIPS32R2-DEF-EL-AS: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EL"
 //
 // RUN: %clang -target mips64-linux-gnu -### \
-// RUN:   -no-integrated-as -fno-pic -c %s 2>&1 \
+// RUN:   -no-integrated-as -fno-pic -mno-abicalls -c %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=MIPS64R2-EB-AS %s
 // MIPS64R2-EB-AS: as{{(.exe)?}}" "-march" "mips64r2" "-mabi" "64" "-mno-shared" "-EB"
 //
@@ -31,7 +31,7 @@
 // MIPS64R2-EB-AS-PIC: as{{(.exe)?}}" "-march" "mips64r2" "-mabi" "64" "-EB" "-KPIC"
 //
 // RUN: %clang -target mips64el-linux-gnu -### \
-// RUN:   -no-integrated-as -c -fno-pic %s 2>&1 \
+// RUN:   -no-integrated-as -c -fno-pic -mno-abicalls %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=MIPS64R2-DEF-EL-AS %s
 // MIPS64R2-DEF-EL-AS: as{{(.exe)?}}" "-march" "mips64r2" "-mabi" "64"  "-mno-shared" "-EL"
 //
@@ -64,7 +64,7 @@
 // MIPS64R2-EL-AS-PIC: as{{(.exe)?}}" "-march" "mips64r2" "-mabi" "64" "-EL" "-KPIC"
 //
 // RUN: %clang -target mips64el-linux-gnu -mabi=64 -### \
-// RUN:   -no-integrated-as -c %s -fno-pic 2>&1 \
+// RUN:   -no-integrated-as -c %s -fno-pic -mno-abicalls 2>&1 \
 // RUN:   | FileCheck -check-prefix=MIPS64R2-EL-AS %s
 // MIPS64R2-EL-AS: as{{(.exe)?}}" "-march" "mips64r2" "-mabi" "64" "-mno-shared" "-EL"
 //
@@ -84,7 +84,7 @@
 // MIPS-OCTEON-PIC: as{{(.exe)?}}" "-march" "octeon" "-mabi" "64" "-EB" "-KPIC"
 //
 // RUN: %clang -target mips64-linux-gnu -march=octeon -### \
-// RUN:   -no-integrated-as -c %s -fno-pic 2>&1 \
+// RUN:   -no-integrated-as -c %s -fno-pic -mno-abicalls 2>&1 \
 // RUN:   | FileCheck -check-prefix=MIPS-OCTEON %s
 // MIPS-OCTEON: as{{(.exe)?}}" "-march" "octeon" "-mabi" "64" "-mno-shared" "-EB"
 //
@@ -144,7 +144,7 @@
 // MIPS-ALIAS-64-PIC: as{{(.exe)?}}" "-march" "mips64" "-mabi" "64" "-EB" "-KPIC"
 //
 // RUN: %clang -target mips64-linux-gnu -mips64 -### \
-// RUN:   -no-integrated-as -c -fno-pic %s 2>&1 \
+// RUN:   -no-integrated-as -c -fno-pic -mno-abicalls %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=MIPS-ALIAS-64 %s
 // MIPS-ALIAS-64: as{{(.exe)?}}" "-march" "mips64" "-mabi" "64" "-mno-shared" "-EB"
 //
@@ -159,7 +159,7 @@
 // MIPS-ALIAS-64R3-PIC: as{{(.exe)?}}" "-march" "mips64r3" "-mabi" "64" "-EB" "-KPIC"
 //
 // RUN: %clang -target mips64-linux-gnu -mips64r3 -### \
-// RUN:   -no-integrated-as -c %s -fno-pic 2>&1 \
+// RUN:   -no-integrated-as -c %s -fno-pic -mno-abicalls 2>&1 \
 // RUN:   | FileCheck -check-prefix=MIPS-ALIAS-64R3 %s
 // MIPS-ALIAS-64R3: as{{(.exe)?}}" "-march" "mips64r3" "-mabi" "64" "-mno-shared" "-EB"
 //
@@ -169,7 +169,7 @@
 // MIPS-ALIAS-64R5-PIC: as{{(.exe)?}}" "-march" "mips64r5" "-mabi" "64" "-EB" "-KPIC"
 //
 // RUN: %clang -target mips64-linux-gnu -mips64r5 -### \
-// RUN:   -no-integrated-as -c %s -fno-pic 2>&1 \
+// RUN:   -no-integrated-as -c %s -fno-pic -mno-abicalls 2>&1 \
 // RUN:   | FileCheck -check-prefix=MIPS-ALIAS-64R5 %s
 // MIPS-ALIAS-64R5: as{{(.exe)?}}" "-march" "mips64r5" "-mabi" "64" "-mno-shared" "-EB"
 //
@@ -179,7 +179,7 @@
 /

[PATCH] D46108: [ARM] Add __ARM_FEATURE_DOTPROD pre-defined macro

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

Looks like a straight forward fix/addition to me.




Comment at: lib/Basic/Targets/ARM.cpp:737
 
+  if (DotProd)
+Builder.defineMacro("__ARM_FEATURE_DOTPROD", "1");

Nit: do we a comment here too that this is Armv8.2-A?


Repository:
  rL LLVM

https://reviews.llvm.org/D46108



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


[PATCH] D46109: [ARM, AArch64] Add intrinsics for dot product instructions

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

I think this looks OK.




Comment at: include/clang/Basic/arm_neon.td:1587
+// v8.2-A dot product instructions
+let ArchGuard = "defined(__ARM_FEATURE_DOTPROD)" in {
+  def DOT : SInst<"vdot", "dd88", "iQiUiQUi">;

Nit: I think it's obvious, but perhaps a comment here, which would be 
consistent with similar remarks in this file, that this this is for both A32 
and A64 (and the one below A64 only)?



Comment at: include/clang/Basic/arm_neon_incl.td:256
 // c: const pointer type
+// 7: vector of 8-bit elements, ignore 'Q' size modifier
+// 8: vector of 8-bit elements, same width as default type

Yes, more modifiers! ;-)



Comment at: test/CodeGen/aarch64-neon-dot-product.c:6
+
+// Test AArch64 v8.2-A dot product intrinsics
+

Same nit as in of the other patches: not sure if we should spell out Armv8.2-A 
or if v8.2-A is actually ok.


Repository:
  rL LLVM

https://reviews.llvm.org/D46109



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


[PATCH] D45815: [libclang] Add options to limit skipping of function bodies

2018-04-26 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov requested changes to this revision.
ilya-biryukov added a comment.
This revision now requires changes to proceed.

> OK, I've rechecked this change. I don't see any obvious mistake :)

I think I got to the bottom of it. We didn't expect a big win, because we 
expect people to not put their non-template code into the header files. Which 
is probably true.
The problem with our reasoning, is that this patch also skip bodies of 
**non-template functions inside template classes**, e.g.

  template 
  struct vector {
 template 
 void append(T* pos, It begin, It end) {
  / * This function won't be skipped, it is a template. */ 
 }
  
 void push_back(T const&) {
  /* However, this function will be skipped! It is not a template! */
 }
  };

So it's not surprising that we get a big win. Template function are (probably) 
much more rare than non-template functions inside templates.

However, note that we will still miss a lot of diagnostics if we skip bodies of 
non-template functions inside templates.
So I don't see much value in an option like this: it still compromises 
correctness of diagnostics even inside the main file, while still missing out 
some performance opportunities that come from skipping the template functions. 
And it makes the code more complex.

We should either have an option that **does not** skip functions inside 
template classes or keep the current boolean value.
We should definitely measure the performance impact of having such an option 
before adding more complexity to the code.
WDYT?

BTW, maybe split this change out into two patches: one that allows to skip 
function bodies only in the preamble, the other that turns SkipFunctionBodies 
boolean into a enum and changes parser, etc.
The ASTUnit changes LG and we could probably LGTM them sooner than the parser 
changes.




Comment at: lib/Parse/ParseCXXInlineMethods.cpp:104
 
-  if (SkipFunctionBodies && (!FnD || Actions.canSkipFunctionBody(FnD)) &&
-  trySkippingFunctionBody()) {
+  if (SkipFunctionBodies != SkipFunctionBodiesKind::None &&
+  (!FnD || Actions.canSkipFunctionBody(FnD)) && trySkippingFunctionBody()) 
{

Can't this be a template too? Do we need to check for it here?


Repository:
  rC Clang

https://reviews.llvm.org/D45815



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


[PATCH] D45212: [HIP] Let CUDA toolchain support HIP language mode and amdgpu

2018-04-26 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked 14 inline comments as done.
yaxunl added a comment.

ping


https://reviews.llvm.org/D45212



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


[PATCH] D46022: [OpenCL] Restrict various keywords in OpenCL C++ mode

2018-04-26 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh updated this revision to Diff 144098.
svenvh edited the summary of this revision.
svenvh added a comment.

Updated patch to reject any thread storage class specifier, not just 
`thread_local`.

Also mark the OpenCL access qualifiers as reserved keywords as per OpenCL C++ 
1.0 s2.2, and add a test for those.


https://reviews.llvm.org/D46022

Files:
  include/clang/Basic/DiagnosticCommonKinds.td
  include/clang/Basic/DiagnosticParseKinds.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/TokenKinds.def
  include/clang/Sema/DeclSpec.h
  lib/Basic/IdentifierTable.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Parse/ParseDecl.cpp
  lib/Parse/ParseStmtAsm.cpp
  lib/Sema/DeclSpec.cpp
  lib/Sema/SemaCast.cpp
  lib/Sema/SemaExprCXX.cpp
  lib/Sema/SemaStmt.cpp
  test/Parser/opencl-cl20.cl
  test/Parser/opencl-cxx-keywords.cl
  test/Parser/opencl-storage-class.cl
  test/SemaOpenCL/storageclass.cl
  test/SemaOpenCLCXX/restricted.cl

Index: test/SemaOpenCLCXX/restricted.cl
===
--- /dev/null
+++ test/SemaOpenCLCXX/restricted.cl
@@ -0,0 +1,73 @@
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=c++ -pedantic -verify -fsyntax-only
+
+// This test checks that various C/C++/OpenCL C constructs are not available in
+// OpenCL C++, according to OpenCL C++ 1.0 Specification Section 2.9.
+
+// Test that typeid is not available in OpenCL C++.
+namespace std {
+  // Provide a dummy std::type_info so that we can use typeid.
+  class type_info {
+int a;
+  };
+}
+__constant std::type_info int_ti = typeid(int);
+// expected-error@-1 {{'typeid' is not supported in OpenCL C++}}
+
+// Test that dynamic_cast is not available in OpenCL C++.
+class A {
+public:
+  int a;
+};
+
+class B : public A {
+  int b;
+};
+
+B *test_dynamic_cast(B *p) {
+  return dynamic_cast(p);
+  // expected-error@-1 {{'dynamic_cast' is not supported in OpenCL C++}}
+}
+
+// Test storage class qualifiers.
+__constant _Thread_local int a = 1;
+// expected-error@-1 {{OpenCL C++ version 1.0 does not support the '_Thread_local' storage class specifier}}
+__constant __thread int b = 2;
+// expected-error@-1 {{OpenCL C++ version 1.0 does not support the '__thread' storage class specifier}}
+kernel void test_storage_classes() {
+  register int x;
+  // expected-error@-1 {{OpenCL C++ version 1.0 does not support the 'register' storage class specifier}}
+  thread_local int y;
+  // expected-error@-1 {{OpenCL C++ version 1.0 does not support the 'thread_local' storage class specifier}}
+}
+
+// Test that access qualifiers are reserved keywords.
+kernel void test_access_qualifiers() {
+  int read_only;
+  // expected-error@-1 {{'read_only' is a reserved keyword in OpenCL C++}}
+  // expected-warning@-2 {{declaration does not declare anything}}
+  int __read_only;
+  // expected-error@-1 {{'__read_only' is a reserved keyword in OpenCL C++}}
+  // expected-warning@-2 {{declaration does not declare anything}}
+  int write_only;
+  // expected-error@-1 {{'write_only' is a reserved keyword in OpenCL C++}}
+  // expected-warning@-2 {{declaration does not declare anything}}
+  int __write_only;
+  // expected-error@-1 {{'__write_only' is a reserved keyword in OpenCL C++}}
+  // expected-warning@-2 {{declaration does not declare anything}}
+  int read_write;
+  // expected-error@-1 {{'read_write' is a reserved keyword in OpenCL C++}}
+  // expected-warning@-2 {{declaration does not declare anything}}
+  int __read_write;
+  // expected-error@-1 {{'__read_write' is a reserved keyword in OpenCL C++}}
+  // expected-warning@-2 {{declaration does not declare anything}}
+}
+
+// Test other keywords that are not available in OpenCL C++.
+kernel void test_misc() {
+  goto label;
+  // expected-error@-1 {{'goto' is not supported in OpenCL C++}}
+label:
+  asm("");
+  // expected-error@-1 {{'asm' is not supported in OpenCL C++}}
+  // expected-warning@-2 {{expression result unused}}
+}
Index: test/SemaOpenCL/storageclass.cl
===
--- test/SemaOpenCL/storageclass.cl
+++ test/SemaOpenCL/storageclass.cl
@@ -10,14 +10,14 @@
 static global float g_global_static_var = 0;   // expected-error {{program scope variable must reside in constant address space}}
 static local float g_local_static_var = 0; // expected-error {{program scope variable must reside in constant address space}}
 static private float g_private_static_var = 0; // expected-error {{program scope variable must reside in constant address space}}
-static generic float g_generic_static_var = 0; // expected-error{{OpenCL version 1.2 does not support the 'generic' type qualifier}} // expected-error {{program scope variable must reside in constant address space}}
+static generic float g_generic_static_var = 0; // expected-error{{OpenCL C version 1.2 does not support the 'generic' type qualifier}} // expected-error {{program scope variable must reside in constant address

[PATCH] D46022: [OpenCL] Restrict various keywords in OpenCL C++ mode

2018-04-26 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh added inline comments.



Comment at: include/clang/Basic/TokenKinds.def:255
+//   KEYNOOPENCL  - This is a keyword that is not supported in OpenCL C
+//  nor in OpenCL C++.
 //   KEYALTIVEC - This is a keyword in AltiVec

rjmccall wrote:
> `KEYNOOPENCL` is dead now, I think.
There are still some other uses of `KEYNOOPENCL` (already there before this 
patch).



Comment at: lib/Sema/DeclSpec.cpp:621
+// OpenCL C++ 1.0 s2.9: the thread_local storage qualifier is not
+// supported.
+case TSCS_thread_local:

rjmccall wrote:
> Do you really care about the spelling of the specifier?  Presumably 
> `__thread` (the GNU extension) and `_Thread_local` (the C11 feature) are 
> unsupported; where are those diagnosed?
Fair enough, I have updated the patch to just reject any thread qualifier here.


https://reviews.llvm.org/D46022



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


[PATCH] D38845: [ASTImporter] Support importing UnresolvedMemberExpr, DependentNameType, DependentScopeDeclRefExpr

2018-04-26 Thread Peter Szecsi via Phabricator via cfe-commits
szepet marked an inline comment as done.
szepet added inline comments.



Comment at: unittests/AST/ASTImporterTest.cpp:1569
+FirstDeclMatcher().match(*TB, Pattern);
+if (!FromDSDRE)
+  return;

martong wrote:
> I think, this `if` would be needed only if the test suite would be 
> parameterized also with `ArgVector{"-fdelayed-template-parsing"}`, but that 
> is not.
Its necessary, since on windows platforms we have that flag by default (so, it 
does not matter that we dont include here, it will be used anyway).



Comment at: unittests/AST/ASTImporterTest.cpp:1573
+auto To = cast(Import(FromDSDRE, Lang_CXX));
+EXPECT_TRUE(FirstDeclMatcher().match(To, Pattern));
+  }

martong wrote:
> It will be hard to notice based on the test output which DSDRE's import was 
> unsuccessful. Therefore I'd unroll the for loop instead, also please see the 
> above comment that it would be more practical to have one FromTU.
I understand the concern, but I am really against the mentioned design. The 
main point of this code is that whenever we would like to add one more test 
cases, then we need to add it to the vector and everything else is done. Other 
than that, I would say that debugging a broken test case is already a "time 
expensive" job, so in that case it wouldnt make much of a different, since you 
need to look at the code closely anyway.


https://reviews.llvm.org/D38845



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


[PATCH] D46115: [ASTImporter] properly import SrcLoc of Attr

2018-04-26 Thread Rafael Stahl via Phabricator via cfe-commits
r.stahl created this revision.
r.stahl added reviewers: NoQ, dcoughlin, xazax.hun, george.karpenkov.
Herald added subscribers: cfe-commits, martong, a.sidorin, rnkovacs.

The ASTImporter was failing to import the SourceLocation field of Attrs.


Repository:
  rC Clang

https://reviews.llvm.org/D46115

Files:
  lib/AST/ASTImporter.cpp


Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -7199,8 +7199,11 @@
 
 Decl *ASTImporter::Imported(Decl *From, Decl *To) {
   if (From->hasAttrs()) {
-for (auto *FromAttr : From->getAttrs())
-  To->addAttr(FromAttr->clone(To->getASTContext()));
+for (auto *FromAttr : From->getAttrs()) {
+  Attr *ToAttr = FromAttr->clone(To->getASTContext());
+  ToAttr->setRange(Import(FromAttr->getRange()));
+  To->addAttr(ToAttr);
+}
   }
   if (From->isUsed()) {
 To->setIsUsed();


Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -7199,8 +7199,11 @@
 
 Decl *ASTImporter::Imported(Decl *From, Decl *To) {
   if (From->hasAttrs()) {
-for (auto *FromAttr : From->getAttrs())
-  To->addAttr(FromAttr->clone(To->getASTContext()));
+for (auto *FromAttr : From->getAttrs()) {
+  Attr *ToAttr = FromAttr->clone(To->getASTContext());
+  ToAttr->setRange(Import(FromAttr->getRange()));
+  To->addAttr(ToAttr);
+}
   }
   if (From->isUsed()) {
 To->setIsUsed();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46115: [ASTImporter] properly import SrcLoc of Attr

2018-04-26 Thread Rafael Stahl via Phabricator via cfe-commits
r.stahl added a comment.

This is unfinished. Posting to make you aware of the issue. There are other 
occurances of imported attrs without importing the srcloc in:

- VisitIndirectFieldDecl
- VisitAttributedStmt

So I was thinking this would suggest to add a public API 
`ASTImporter::Import(Attr *)`. Does it make sense to add this? Is there 
anything else I need to do to change public API?

Merging of Attr would also be missing and I wouldn't know how to approach this.

Testing also added soon!


Repository:
  rC Clang

https://reviews.llvm.org/D46115



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


[PATCH] D38845: [ASTImporter] Support importing UnresolvedMemberExpr, DependentNameType, DependentScopeDeclRefExpr

2018-04-26 Thread Aleksei Sidorin via Phabricator via cfe-commits
a.sidorin requested changes to this revision.
a.sidorin added inline comments.
This revision now requires changes to proceed.



Comment at: unittests/AST/ASTImporterTest.cpp:1569
+FirstDeclMatcher().match(*TB, Pattern);
+if (!FromDSDRE)
+  return;

szepet wrote:
> martong wrote:
> > I think, this `if` would be needed only if the test suite would be 
> > parameterized also with `ArgVector{"-fdelayed-template-parsing"}`, but that 
> > is not.
> Its necessary, since on windows platforms we have that flag by default (so, 
> it does not matter that we dont include here, it will be used anyway).
The declaration should be always present independently of flags so `if` is 
invalid here. To achieve this, we use explicit template instantiations in the 
test code. See `ImportCXXDependentScopeMemberExpr` test for reference. Explicit 
instantiations also allow us to find errors in the template code itself.



Comment at: unittests/AST/ASTImporterTest.cpp:1577
+
+INSTANTIATE_TEST_CASE_P(ParameterizedTests, NoDelayedTemplateParsing,
+::testing::Values(ArgVector()), );

Please don't do this - always test the code with both flag options. Explicit 
instantiations will help you to do this. Otherwise, windows buildbot will add 
the flag on its own causing the test to crash after the commit.


https://reviews.llvm.org/D38845



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


[PATCH] D44609: [Clang-Format] New option BreakBeforeLambdaBody to manage lambda line break inside function parameter call

2018-04-26 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added inline comments.



Comment at: include/clang/Format/Format.h:891
+  /// \endcode
+  bool BreakBeforeLambdaBody;
+

I'd just make that default for Allman style.



Comment at: lib/Format/TokenAnnotator.cpp:2844
   if (isAllmanBrace(Left) || isAllmanBrace(Right))
-return (Line.startsWith(tok::kw_enum) && Style.BraceWrapping.AfterEnum) ||
+return (Line.containsBefore(Right, TT_LambdaLSquare) && 
Style.BreakBeforeLambdaBody) ||
+   (Line.startsWith(tok::kw_enum) && Style.BraceWrapping.AfterEnum) ||

Instead of parsing the whole line again, which can lead to false positives, you 
can add a TokenType for LambdaLBrace while parsing and use that here.


Repository:
  rC Clang

https://reviews.llvm.org/D44609



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


[PATCH] D46024: [clang-format] Add SpaceBeforeCpp11BracedList option.

2018-04-26 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added a comment.

Is this written down somewhere? https://webkit.org/code-style-guidelines/ 
doesn't seem to mention it.


Repository:
  rC Clang

https://reviews.llvm.org/D46024



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


[PATCH] D44684: [mips] Improve handling of -fno-[pic/PIC] option

2018-04-26 Thread Simon Dardis via Phabricator via cfe-commits
sdardis added inline comments.



Comment at: include/clang/Basic/DiagnosticDriverKinds.td:340
+  "ignoring '%0' option as it cannot be used with "
+  "explicit use of -mabicalls and the N64 ABI">,
   InGroup;

Use the %select{optionA|optionB|..|optionZ}$NUM operator here like:

"cannot be used with the %select{explicit|implicit}1 usage of -mabicalls and 
the N64 ABI"

Which eliminates the need for two separate warnings.



Comment at: lib/Driver/ToolChains/Arch/Mips.cpp:242-250
+if (!ABICallsArg) {
+  D.Diag(diag::warn_drv_unsupported_pic_with_implicit_mabicalls)
+  << LastPICArg->getAsString(Args);
+  NonPIC = false;
+} else if (UseAbiCalls) {
+  D.Diag(diag::warn_drv_unsupported_pic_with_explicit_mabicalls)
+  << LastPICArg->getAsString(Args);

Then all of this can be simplified.


Repository:
  rL LLVM

https://reviews.llvm.org/D44684



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


[PATCH] D32859: [Analyzer] Iterator Checker - Part 5: Move Assignment of Containers

2018-04-26 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 144106.
baloghadamsoftware added a comment.
Herald added a reviewer: george.karpenkov.

One test failed after rebased to the current master branch. Depending on the 
internal implementation of the iterator and the move operation of the container 
it could happen that after moving a container the begin() or end() of the 
target of the move returns an already existing iterator position to the source 
of the move which is wrong. Therefore we must first check for begin() and end() 
and only then check for the existence of the iterator position of the return 
value of a function returning an iterator.


https://reviews.llvm.org/D32859

Files:
  lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
  test/Analysis/mismatched-iterator.cpp

Index: test/Analysis/mismatched-iterator.cpp
===
--- test/Analysis/mismatched-iterator.cpp
+++ test/Analysis/mismatched-iterator.cpp
@@ -15,11 +15,48 @@
   std::copy(v1.cbegin(), v1.cend(), v2.begin()); // no-warning
 }
 
+void good_move_find1(std::vector &v1, std::vector &v2, int n) {
+  auto i0 = v2.cbegin();
+  v1 = std::move(v2);
+  std::find(i0, v1.cend(), n); // no-warning
+}
+
+void good_move_find2(std::vector &v1, std::vector &v2, int n) {
+  auto i0 = --v2.cend();
+  v1 = std::move(v2);
+  std::find(i0, v1.cend(), n); // no-warning
+}
+
+void good_move_find3(std::vector &v1, std::vector &v2, int n) {
+  auto i0 = v2.cend();
+  v1 = std::move(v2);
+  v2.push_back(n);
+  std::find(v2.cbegin(), i0, n); // no-warning
+}
+
 void bad_find(std::vector &v1, std::vector &v2, int n) {
   std::find(v1.cbegin(), v2.cend(), n); // expected-warning{{Iterator access mismatched}}
 }
 
 void bad_find_first_of(std::vector &v1, std::vector &v2) {
   std::find_first_of(v1.cbegin(), v2.cend(), v2.cbegin(), v2.cend()); // expected-warning{{Iterator access mismatched}}
   std::find_first_of(v1.cbegin(), v1.cend(), v2.cbegin(), v1.cend()); // expected-warning{{Iterator access mismatched}}
 }
+
+void bad_move_find1(std::vector &v1, std::vector &v2, int n) {
+  auto i0 = v2.cbegin();
+  v1 = std::move(v2);
+  std::find(i0, v2.cend(), n); // expected-warning{{Iterator access mismatched}}
+}
+
+void bad_move_find2(std::vector &v1, std::vector &v2, int n) {
+  auto i0 = --v2.cend();
+  v1 = std::move(v2);
+  std::find(i0, v2.cend(), n); // expected-warning{{Iterator access mismatched}}
+}
+
+void bad_move_find3(std::vector &v1, std::vector &v2, int n) {
+  auto i0 = v2.cend();
+  v1 = std::move(v2);
+  std::find(v1.cbegin(), i0, n); // expected-warning{{Iterator access mismatched}}
+}
Index: lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
+++ lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
@@ -114,6 +114,10 @@
 return IteratorPosition(Cont, Valid, NewOf);
   }
 
+  IteratorPosition reAssign(const MemRegion *NewCont) const {
+return IteratorPosition(NewCont, Valid, Offset);
+  }
+
   bool operator==(const IteratorPosition &X) const {
 return Cont == X.Cont && Valid == X.Valid && Offset == X.Offset;
   }
@@ -219,7 +223,9 @@
  const SVal &Cont) const;
   void assignToContainer(CheckerContext &C, const Expr *CE, const SVal &RetVal,
  const MemRegion *Cont) const;
-  void handleAssign(CheckerContext &C, const SVal &Cont) const;
+  void handleAssign(CheckerContext &C, const SVal &Cont,
+const Expr *CE = nullptr,
+const SVal &OldCont = UndefinedVal()) const;
   void verifyRandomIncrOrDecr(CheckerContext &C, OverloadedOperatorKind Op,
   const SVal &RetVal, const SVal &LHS,
   const SVal &RHS) const;
@@ -317,6 +323,17 @@
 bool Equal);
 ProgramStateRef invalidateAllIteratorPositions(ProgramStateRef State,
const MemRegion *Cont);
+ProgramStateRef reassignAllIteratorPositions(ProgramStateRef State,
+ const MemRegion *Cont,
+ const MemRegion *NewCont);
+ProgramStateRef reassignAllIteratorPositionsUnless(ProgramStateRef State,
+   const MemRegion *Cont,
+   const MemRegion *NewCont,
+   SymbolRef Offset,
+   BinaryOperator::Opcode Opc);
+ProgramStateRef replaceSymbolInIteratorPositionsIf(
+ProgramStateRef State, SValBuilder &SVB, SymbolRef OldSym,
+SymbolRef NewSym, SymbolRef CondSym, BinaryOperator::Opcode Opc);
 const ContainerData *getContainerData(ProgramStateRef State,
   const MemRegion *Cont);
 ProgramStateRef setContainerData(Prog

[PATCH] D46000: [AST] Added a helper to extract a user-friendly text of a comment.

2018-04-26 Thread Eric Liu via Phabricator via cfe-commits
ioeric added a comment.

Looks good. We still need tests though :)




Comment at: lib/AST/RawCommentList.cpp:376
+SourceMgr.getSpellingColumnNumber(Tok.getLocation(), &LocInvalid);
+if (LocInvalid)
+  TokColumn = 0;

This is a bit confusing... Could you please add comments about the behavior 
here (as chatted offline)?



Comment at: lib/AST/RawCommentList.cpp:394
+: std::min(WhitespaceLen,
+   (size_t)std::max((int)IndentColumn - (int)TokColumn, 
0));
+llvm::StringRef Trimmed = TokText.drop_front(SkipLen);

use `static_cast` instead of conversions.



Comment at: lib/AST/RawCommentList.cpp:405
+}
+// We've reached the end of the line.
+return false;

I think it's end of file?


Repository:
  rC Clang

https://reviews.llvm.org/D46000



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


[PATCH] D46081: [analyzer] Expand conversion check to check more expressions for overflow and underflow

2018-04-26 Thread Paul Fultz II via Phabricator via cfe-commits
pfultz2 added a comment.

> While I understand extending the analyzer to cover more is a good approach, 
> there is -Wconversion which seemingly covers this -- or at least the trivial 
> case(?):

Yes, but it won't catch something like this, which is more interesting:

  void g(unsigned);
  void f(int x) {
  if (x < 0) return;
  g(x - 1);
  }


Repository:
  rC Clang

https://reviews.llvm.org/D46081



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


[PATCH] D46081: [analyzer] Expand conversion check to check more expressions for overflow and underflow

2018-04-26 Thread Paul Fultz II via Phabricator via cfe-commits
pfultz2 added inline comments.



Comment at: lib/StaticAnalyzer/Checkers/ConversionChecker.cpp:77
 if (Opc == BO_Assign) {
-  LossOfSign = isLossOfSign(Cast, C);
-  LossOfPrecision = isLossOfPrecision(Cast, Cast->getType(), C);
+  if (!B->getRHS()->isIntegerConstantExpr(C.getASTContext())) {
+LossOfSign = isLossOfSign(Cast, C);

george.karpenkov wrote:
> Sorry, I don't quite follow: why we don't want to warn when RHS is an integer 
> constant?
Because we want to treat `unsigned i = -1` as an explicit conversion. Ideally, 
I would like to just check that the RHS is a literal, but this seems like the 
closest way to do that.


Repository:
  rC Clang

https://reviews.llvm.org/D46081



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


[PATCH] D32860: [Analyzer] Iterator Checker - Part 6: Mismatched iterator checker for constructors and comparisons

2018-04-26 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 144110.
baloghadamsoftware added a comment.
Herald added a reviewer: george.karpenkov.

Rebased to Part 5.


https://reviews.llvm.org/D32860

Files:
  lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
  test/Analysis/mismatched-iterator.cpp

Index: test/Analysis/mismatched-iterator.cpp
===
--- test/Analysis/mismatched-iterator.cpp
+++ test/Analysis/mismatched-iterator.cpp
@@ -3,6 +3,10 @@
 
 #include "Inputs/system-header-simulator-cxx.h"
 
+void good_ctor(std::vector &v) {
+  std::vector new_v(v.cbegin(), v.cend()); // no-warning
+}
+
 void good_find(std::vector &v, int n) {
   std::find(v.cbegin(), v.cend(), n); // no-warning
 }
@@ -34,6 +38,14 @@
   std::find(v2.cbegin(), i0, n); // no-warning
 }
 
+void good_comparison(std::vector &v) {
+  if (v.cbegin() == v.cend()) {} // no-warning
+}
+
+void bad_ctor(std::vector &v1, std::vector &v2) {
+  std::vector new_v(v1.cbegin(), v2.cend()); // expected-warning{{Iterator access mismatched}}
+}
+
 void bad_find(std::vector &v1, std::vector &v2, int n) {
   std::find(v1.cbegin(), v2.cend(), n); // expected-warning{{Iterator access mismatched}}
 }
@@ -60,3 +72,9 @@
   v1 = std::move(v2);
   std::find(v1.cbegin(), i0, n); // expected-warning{{Iterator access mismatched}}
 }
+
+void bad_comparison(std::vector &v1, std::vector &v2) {
+  if (v1.cbegin() != v2.cend()) { // expected-warning{{Iterator access mismatched}}
+*v1.cbegin();
+  }
+}
Index: lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
+++ lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
@@ -197,6 +197,7 @@
 
 class IteratorChecker
 : public Checker,
  check::PreStmt,
  check::PostStmt,
  check::LiveSymbols, check::DeadSymbols,
@@ -229,14 +230,19 @@
   void verifyRandomIncrOrDecr(CheckerContext &C, OverloadedOperatorKind Op,
   const SVal &RetVal, const SVal &LHS,
   const SVal &RHS) const;
+  void verifyMatch(CheckerContext &C, const SVal &Iter,
+   const MemRegion *Cont) const;
   void verifyMatch(CheckerContext &C, const SVal &Iter1,
const SVal &Iter2) const;
 
   void reportOutOfRangeBug(const StringRef &Message, const SVal &Val,
CheckerContext &C, ExplodedNode *ErrNode) const;
   void reportMismatchedBug(const StringRef &Message, const SVal &Val1,
const SVal &Val2, CheckerContext &C,
ExplodedNode *ErrNode) const;
+  void reportMismatchedBug(const StringRef &Message, const SVal &Val,
+   const MemRegion *Reg, CheckerContext &C,
+   ExplodedNode *ErrNode) const;
   void reportInvalidatedBug(const StringRef &Message, const SVal &Val,
 CheckerContext &C, ExplodedNode *ErrNode) const;
 
@@ -255,6 +261,7 @@
 
   void checkPreCall(const CallEvent &Call, CheckerContext &C) const;
   void checkPostCall(const CallEvent &Call, CheckerContext &C) const;
+  void checkPreStmt(const CXXConstructExpr *CCE, CheckerContext &C) const;
   void checkPreStmt(const CXXOperatorCallExpr *COCE, CheckerContext &C) const;
   void checkPostStmt(const MaterializeTemporaryExpr *MTE,
  CheckerContext &C) const;
@@ -278,6 +285,7 @@
 
 bool isIteratorType(const QualType &Type);
 bool isIterator(const CXXRecordDecl *CRD);
+bool isComparisonOperator(OverloadedOperatorKind OK);
 bool isBeginCall(const FunctionDecl *Func);
 bool isEndCall(const FunctionDecl *Func);
 bool isAssignmentOperator(OverloadedOperatorKind OK);
@@ -396,6 +404,28 @@
   } else {
 verifyDereference(C, Call.getArgSVal(0));
   }
+} else if (ChecksEnabled[CK_MismatchedIteratorChecker] &&
+   isComparisonOperator(Func->getOverloadedOperator())) {
+  // Check for comparisons of iterators of different containers
+  if (const auto *InstCall = dyn_cast(&Call)) {
+if (Call.getNumArgs() < 1)
+  return;
+
+if (!isIteratorType(InstCall->getCXXThisExpr()->getType()) ||
+!isIteratorType(Call.getArgExpr(0)->getType()))
+  return;
+
+verifyMatch(C, InstCall->getCXXThisVal(), Call.getArgSVal(0));
+  } else {
+if (Call.getNumArgs() < 2)
+  return;
+
+if (!isIteratorType(Call.getArgExpr(0)->getType()) ||
+!isIteratorType(Call.getArgExpr(1)->getType()))
+  return;
+
+verifyMatch(C, Call.getArgSVal(0), Call.getArgSVal(1));
+  }
 }
   } else if (!isa(&Call)) {
 // The main purpose of iterators is to abstract away from different
@@ -571,6 +601,31 @@
   }
 }
 
+void IteratorChecker::checkPreStmt(const CXXConstructExpr *CCE,
+   CheckerContext &C

[PATCH] D44387: [x86] Introduce the pconfig/encl[u|s|v] intrinsics

2018-04-26 Thread Gabor Buella via Phabricator via cfe-commits
GBuella updated this revision to Diff 144112.

https://reviews.llvm.org/D44387

Files:
  include/clang/Basic/BuiltinsX86.def
  include/clang/Driver/Options.td
  lib/Basic/Targets/X86.cpp
  lib/Basic/Targets/X86.h
  lib/CodeGen/CGBuiltin.cpp
  lib/Headers/CMakeLists.txt
  lib/Headers/cpuid.h
  lib/Headers/module.modulemap
  lib/Headers/pconfigintrin.h
  lib/Headers/sgxintrin.h
  lib/Headers/x86intrin.h
  test/CodeGen/builtins-x86.c
  test/CodeGen/pconfig.c
  test/CodeGen/sgx.c
  test/Driver/x86-target-features.c
  test/Preprocessor/predefined-arch-macros.c

Index: test/Preprocessor/predefined-arch-macros.c
===
--- test/Preprocessor/predefined-arch-macros.c
+++ test/Preprocessor/predefined-arch-macros.c
@@ -1204,6 +1204,7 @@
 // CHECK_ICX_M32: #define __MMX__ 1
 // CHECK_ICX_M32: #define __MPX__ 1
 // CHECK_ICX_M32: #define __PCLMUL__ 1
+// CHECK_ICX_M32: #define __PCONFIG__ 1
 // CHECK_ICX_M32: #define __PKU__ 1
 // CHECK_ICX_M32: #define __POPCNT__ 1
 // CHECK_ICX_M32: #define __PRFCHW__ 1
@@ -1261,6 +1262,7 @@
 // CHECK_ICX_M64: #define __MMX__ 1
 // CHECK_ICX_M64: #define __MPX__ 1
 // CHECK_ICX_M64: #define __PCLMUL__ 1
+// CHECK_ICX_M64: #define __PCONFIG__ 1
 // CHECK_ICX_M64: #define __PKU__ 1
 // CHECK_ICX_M64: #define __POPCNT__ 1
 // CHECK_ICX_M64: #define __PRFCHW__ 1
Index: test/Driver/x86-target-features.c
===
--- test/Driver/x86-target-features.c
+++ test/Driver/x86-target-features.c
@@ -149,3 +149,8 @@
 // RUN: %clang -target i386-linux-gnu -mno-waitpkg %s -### -o %t.o 2>&1 | FileCheck -check-prefix=NO-WAITPKG %s
 // WAITPKG: "-target-feature" "+waitpkg"
 // NO-WAITPKG: "-target-feature" "-waitpkg"
+
+// RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mpconfig %s -### -o %t.o 2>&1 | FileCheck -check-prefix=PCONFIG %s
+// RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mno-pconfig %s -### -o %t.o 2>&1 | FileCheck -check-prefix=NO-PCONFIG %s
+// PCONFIG: "-target-feature" "+pconfig"
+// NO-PCONFIG: "-target-feature" "-pconfig"
Index: test/CodeGen/sgx.c
===
--- /dev/null
+++ test/CodeGen/sgx.c
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 %s -ffreestanding -triple x86_64-unknown-unknown -emit-llvm -target-feature +sgx -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-64
+// RUN: %clang_cc1 %s -ffreestanding -triple i386-unknown-unknown -emit-llvm -target-feature +sgx -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-32
+
+#include 
+
+#include 
+
+unsigned int test_encls(unsigned int leaf, size_t arguments[]) {
+  //CHECK-LABEL: @test_encls
+  //CHECK-64: @llvm.x86.encls.64
+  //CHECK-32: @llvm.x86.encls.32
+  return _encls_u32(leaf, arguments);
+}
+
+unsigned int test_enclu(unsigned int leaf, size_t arguments[]) {
+  //CHECK-LABEL: @test_enclu
+  //CHECK-64: @llvm.x86.enclu.64
+  //CHECK-32: @llvm.x86.enclu.32
+  return _enclu_u32(leaf, arguments);
+}
+
+unsigned int test_enclv(unsigned int leaf, size_t arguments[]) {
+  //CHECK-LABEL: @test_enclv
+  //CHECK-64: @llvm.x86.enclv.64
+  //CHECK-32: @llvm.x86.enclv.32
+  return _enclv_u32(leaf, arguments);
+}
Index: test/CodeGen/pconfig.c
===
--- /dev/null
+++ test/CodeGen/pconfig.c
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 %s -ffreestanding -triple x86_64-apple-darwin -emit-llvm -target-feature +pconfig -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-64
+// RUN: %clang_cc1 %s -ffreestanding -triple i386 -emit-llvm -target-feature +pconfig -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-32
+
+#include 
+
+#include 
+
+unsigned int test_pconfig(unsigned int leaf, size_t arguments[]) {
+  //CHECK-LABEL: @test_pconfig
+  //CHECK-64: @llvm.x86.pconfig.64
+  //CHECK-32: @llvm.x86.pconfig.32
+  return _pconfig_u32(leaf, arguments);
+}
+
Index: test/CodeGen/builtins-x86.c
===
--- test/CodeGen/builtins-x86.c
+++ test/CodeGen/builtins-x86.c
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -DUSE_64 -triple x86_64-unknown-unknown -target-feature +fxsr -target-feature +avx -target-feature +xsaveopt -target-feature +xsaves -target-feature +xsavec -target-feature +mwaitx -target-feature +clzero -target-feature +ibt -target-feature +shstk -target-feature +wbnoinvd -target-feature +cldemote -emit-llvm -o %t %s
-// RUN: %clang_cc1 -DUSE_ALL -triple x86_64-unknown-unknown -target-feature +fxsr -target-feature +avx -target-feature +xsaveopt -target-feature +xsaves -target-feature +xsavec -target-feature +mwaitx -target-feature +ibt -target-feature +shstk -target-feature +clzero -target-feature +wbnoinvd -target-feature +cldemote -fsyntax-only -o %t %s
+// RUN: %clang_cc1 -DUSE_64 -triple x86_64-unknown-unknown -target-feature +fxsr -target-feature +avx -target-feature +xsaveopt -target-feature +xsaves -target-fea

[PATCH] D44387: [x86] Introduce the pconfig/encl[u|s|v] intrinsics

2018-04-26 Thread Gabor Buella via Phabricator via cfe-commits
GBuella updated this revision to Diff 144113.

https://reviews.llvm.org/D44387

Files:
  include/clang/Basic/BuiltinsX86.def
  include/clang/Driver/Options.td
  lib/Basic/Targets/X86.cpp
  lib/Basic/Targets/X86.h
  lib/CodeGen/CGBuiltin.cpp
  lib/Headers/CMakeLists.txt
  lib/Headers/cpuid.h
  lib/Headers/module.modulemap
  lib/Headers/pconfigintrin.h
  lib/Headers/sgxintrin.h
  lib/Headers/x86intrin.h
  test/CodeGen/builtins-x86.c
  test/CodeGen/pconfig.c
  test/CodeGen/sgx.c
  test/Driver/x86-target-features.c
  test/Preprocessor/predefined-arch-macros.c

Index: test/Preprocessor/predefined-arch-macros.c
===
--- test/Preprocessor/predefined-arch-macros.c
+++ test/Preprocessor/predefined-arch-macros.c
@@ -1204,6 +1204,7 @@
 // CHECK_ICX_M32: #define __MMX__ 1
 // CHECK_ICX_M32: #define __MPX__ 1
 // CHECK_ICX_M32: #define __PCLMUL__ 1
+// CHECK_ICX_M32: #define __PCONFIG__ 1
 // CHECK_ICX_M32: #define __PKU__ 1
 // CHECK_ICX_M32: #define __POPCNT__ 1
 // CHECK_ICX_M32: #define __PRFCHW__ 1
@@ -1261,6 +1262,7 @@
 // CHECK_ICX_M64: #define __MMX__ 1
 // CHECK_ICX_M64: #define __MPX__ 1
 // CHECK_ICX_M64: #define __PCLMUL__ 1
+// CHECK_ICX_M64: #define __PCONFIG__ 1
 // CHECK_ICX_M64: #define __PKU__ 1
 // CHECK_ICX_M64: #define __POPCNT__ 1
 // CHECK_ICX_M64: #define __PRFCHW__ 1
Index: test/Driver/x86-target-features.c
===
--- test/Driver/x86-target-features.c
+++ test/Driver/x86-target-features.c
@@ -149,3 +149,8 @@
 // RUN: %clang -target i386-linux-gnu -mno-waitpkg %s -### -o %t.o 2>&1 | FileCheck -check-prefix=NO-WAITPKG %s
 // WAITPKG: "-target-feature" "+waitpkg"
 // NO-WAITPKG: "-target-feature" "-waitpkg"
+
+// RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mpconfig %s -### -o %t.o 2>&1 | FileCheck -check-prefix=PCONFIG %s
+// RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mno-pconfig %s -### -o %t.o 2>&1 | FileCheck -check-prefix=NO-PCONFIG %s
+// PCONFIG: "-target-feature" "+pconfig"
+// NO-PCONFIG: "-target-feature" "-pconfig"
Index: test/CodeGen/sgx.c
===
--- /dev/null
+++ test/CodeGen/sgx.c
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 %s -ffreestanding -triple x86_64-unknown-unknown -emit-llvm -target-feature +sgx -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-64
+// RUN: %clang_cc1 %s -ffreestanding -triple i386-unknown-unknown -emit-llvm -target-feature +sgx -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-32
+
+#include 
+
+#include 
+
+unsigned int test_encls(unsigned int leaf, size_t arguments[]) {
+  //CHECK-LABEL: @test_encls
+  //CHECK-64: @llvm.x86.encls.64
+  //CHECK-32: @llvm.x86.encls.32
+  return _encls_u32(leaf, arguments);
+}
+
+unsigned int test_enclu(unsigned int leaf, size_t arguments[]) {
+  //CHECK-LABEL: @test_enclu
+  //CHECK-64: @llvm.x86.enclu.64
+  //CHECK-32: @llvm.x86.enclu.32
+  return _enclu_u32(leaf, arguments);
+}
+
+unsigned int test_enclv(unsigned int leaf, size_t arguments[]) {
+  //CHECK-LABEL: @test_enclv
+  //CHECK-64: @llvm.x86.enclv.64
+  //CHECK-32: @llvm.x86.enclv.32
+  return _enclv_u32(leaf, arguments);
+}
Index: test/CodeGen/pconfig.c
===
--- /dev/null
+++ test/CodeGen/pconfig.c
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 %s -ffreestanding -triple x86_64-apple-darwin -emit-llvm -target-feature +pconfig -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-64
+// RUN: %clang_cc1 %s -ffreestanding -triple i386 -emit-llvm -target-feature +pconfig -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-32
+
+#include 
+
+#include 
+
+unsigned int test_pconfig(unsigned int leaf, size_t arguments[]) {
+  //CHECK-LABEL: @test_pconfig
+  //CHECK-64: @llvm.x86.pconfig.64
+  //CHECK-32: @llvm.x86.pconfig.32
+  return _pconfig_u32(leaf, arguments);
+}
+
Index: test/CodeGen/builtins-x86.c
===
--- test/CodeGen/builtins-x86.c
+++ test/CodeGen/builtins-x86.c
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -DUSE_64 -triple x86_64-unknown-unknown -target-feature +fxsr -target-feature +avx -target-feature +xsaveopt -target-feature +xsaves -target-feature +xsavec -target-feature +mwaitx -target-feature +clzero -target-feature +ibt -target-feature +shstk -target-feature +wbnoinvd -target-feature +cldemote -emit-llvm -o %t %s
-// RUN: %clang_cc1 -DUSE_ALL -triple x86_64-unknown-unknown -target-feature +fxsr -target-feature +avx -target-feature +xsaveopt -target-feature +xsaves -target-feature +xsavec -target-feature +mwaitx -target-feature +ibt -target-feature +shstk -target-feature +clzero -target-feature +wbnoinvd -target-feature +cldemote -fsyntax-only -o %t %s
+// RUN: %clang_cc1 -DUSE_64 -triple x86_64-unknown-unknown -target-feature +fxsr -target-feature +avx -target-feature +xsaveopt -target-feature +xsaves -target-fea

[PATCH] D42966: Fix USR generation in the presence of #line directives or linemarkes

2018-04-26 Thread Mikhail Ramalho via Phabricator via cfe-commits
mikhail.ramalho added a subscriber: rsmith.
mikhail.ramalho added a comment.

Hi,

> Or is the that whenever there's a `#line` directive we get into a
>  "virtual" file that's not registered in the `SourceManager`?

The virtual file is actually registered in the SourceManager but the
FileEntry for it is NULL (USRGeneration.cpp:33), which forces printLoc to
return true (USRGeneration.cpp:38) and the USR is not generated.

I believe the USR gen for params should have follow the functionDecl
convention. I'm reworking the patch now.

> int func(int param1);
>  int func(int param2);
>  // param1 and param2 could both have the same USR, but different names.
>  That might (or might not) be surprising.

I agree here, they should have the same USR.


Repository:
  rC Clang

https://reviews.llvm.org/D42966



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


[PATCH] D46019: [ASTImporter] Fix isa cast assert

2018-04-26 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

Guys, I still don't have commit rights, could you please help me with the 
commit? (I think one more good quality patch and then I could request commit 
rights for myself ...)


Repository:
  rC Clang

https://reviews.llvm.org/D46019



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


[PATCH] D46081: [analyzer] Expand conversion check to check more expressions for overflow and underflow

2018-04-26 Thread Paul Fultz II via Phabricator via cfe-commits
pfultz2 added a comment.

> Have you tried on any large codebases?

This check is not available to the user yet. I can move it to core if you want.


Repository:
  rC Clang

https://reviews.llvm.org/D46081



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


[PATCH] D45532: [StaticAnalyzer] Checker to find uninitialized fields after a constructor call

2018-04-26 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus updated this revision to Diff 144119.
Szelethus added a comment.

Fixes according to inline comments.


https://reviews.llvm.org/D45532

Files:
  include/clang/StaticAnalyzer/Checkers/Checkers.td
  lib/StaticAnalyzer/Checkers/CMakeLists.txt
  lib/StaticAnalyzer/Checkers/CtorUninitializedMemberChecker.cpp
  test/Analysis/Inputs/system-header-simulator-ctor-uninitialized-member.h
  test/Analysis/ctor-uninitialized-member-inheritance.cpp
  test/Analysis/ctor-uninitialized-member.cpp

Index: test/Analysis/ctor-uninitialized-member.cpp
===
--- /dev/null
+++ test/Analysis/ctor-uninitialized-member.cpp
@@ -0,0 +1,1449 @@
+//RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.cplusplus.CtorUninitializedMember -analyzer-config alpha.cplusplus.CtorUninitializedMember:Pedantic=true -std=c++11 -DPEDANTIC -verify %s
+
+//RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.cplusplus.CtorUninitializedMember -std=c++11 -verify %s
+
+//===--===//
+// Default constructor test.
+//===--===//
+
+class CompilerGeneratedConstructorTest {
+  int a, b, c, d, e, f, g, h, i, j;
+
+public:
+  CompilerGeneratedConstructorTest() = default;
+};
+
+void f000() {
+  CompilerGeneratedConstructorTest();
+}
+
+#ifdef PEDANTIC
+class DefaultConstructorTest {
+  int a; // expected-note{{uninitialized field 'this->a'}}
+
+public:
+  DefaultConstructorTest();
+};
+
+DefaultConstructorTest::DefaultConstructorTest() = default;
+
+void f00() {
+  DefaultConstructorTest(); // expected-warning{{1 uninitialized field}}
+}
+#else
+class DefaultConstructorTest {
+  int a;
+
+public:
+  DefaultConstructorTest();
+};
+
+DefaultConstructorTest::DefaultConstructorTest() = default;
+
+void f00() {
+  DefaultConstructorTest();
+}
+#endif // PEDANTIC
+
+//===--===//
+// Initializer list test.
+//===--===//
+
+class InitListTest1 {
+  int a;
+  int b;
+
+public:
+  InitListTest1()
+  : a(1),
+b(2) {
+// All good!
+  }
+};
+
+void f01() {
+  InitListTest1();
+}
+
+class InitListTest2 {
+  int a;
+  int b; // expected-note{{uninitialized field 'this->b'}}
+
+public:
+  InitListTest2()
+  : a(3) {} // expected-warning{{1 uninitialized field}}
+};
+
+void f02() {
+  InitListTest2();
+}
+
+class InitListTest3 {
+  int a; // expected-note{{uninitialized field 'this->a'}}
+  int b;
+
+public:
+  InitListTest3()
+  : b(4) {} // expected-warning{{1 uninitialized field}}
+};
+
+void f03() {
+  InitListTest3();
+}
+
+//===--===//
+// Constructor body test.
+//===--===//
+
+class CtorBodyTest1 {
+  int a, b;
+
+public:
+  CtorBodyTest1() {
+a = 5;
+b = 6;
+// All good!
+  }
+};
+
+void f04() {
+  CtorBodyTest1();
+}
+
+class CtorBodyTest2 {
+  int a;
+  int b; // expected-note{{uninitialized field 'this->b'}}
+
+public:
+  CtorBodyTest2() {
+a = 7; // expected-warning{{1 uninitialized field}}
+  }
+};
+
+void f05() {
+  CtorBodyTest2();
+}
+
+class CtorBodyTest3 {
+  int a; // expected-note{{uninitialized field 'this->a'}}
+  int b;
+
+public:
+  CtorBodyTest3() {
+b = 8; // expected-warning{{1 uninitialized field}}
+  }
+};
+
+void f06() {
+  CtorBodyTest3();
+}
+
+#ifdef PEDANTIC
+class CtorBodyTest4 {
+  int a; // expected-note{{uninitialized field 'this->a'}}
+  int b; // expected-note{{uninitialized field 'this->b'}}
+
+public:
+  CtorBodyTest4() {}
+};
+
+void f07() {
+  CtorBodyTest4(); // expected-warning{{2 uninitialized fields}}
+}
+#else
+class CtorBodyTest4 {
+  int a;
+  int b;
+
+public:
+  CtorBodyTest4() {}
+};
+
+void f07() {
+  CtorBodyTest4();
+}
+#endif
+
+//===--===//
+// Constructor delegation test.
+//===--===//
+
+class CtorDelegationTest1 {
+  int a;
+  int b;
+
+public:
+  CtorDelegationTest1(int)
+  : a(9) {
+// leaves 'b' unintialized, but we'll never check this function
+  }
+
+  CtorDelegationTest1()
+  : CtorDelegationTest1(int{}) { // Initializing 'a'
+b = 10;
+// All good!
+  }
+};
+
+void f08() {
+  CtorDelegationTest1();
+}
+
+class CtorDelegationTest2 {
+  int a; // expected-note{{uninitialized field 'this->a'}}
+  int b;
+
+public:
+  CtorDelegationTest2(int)
+  : b(11) {
+// leaves 'a' unintialized, but we'll never check this function
+  }
+
+  CtorDelegationTest2()
+  : CtorDelegationTest2(int{}) { // expected-warning{{1 uninitialized field}}
+  }
+};
+
+void f09() {
+  CtorDelegationTest2();
+}
+
+//===

[PATCH] D42966: Fix USR generation in the presence of #line directives or linemarkes

2018-04-26 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added subscribers: sammccall, ioeric, hokein, bkramer.
ilya-biryukov added a comment.

In https://reviews.llvm.org/D42966#1079438, @mikhail.ramalho wrote:

> The virtual file is actually registered in the SourceManager but the
>  FileEntry for it is NULL (USRGeneration.cpp:33), which forces printLoc to
>  return true (USRGeneration.cpp:38) and the USR is not generated.


I still don't get why the file is virtual. Looking at the code in 
`SourceManager`, presumed location uses `FileEntry` of passed location 
(actually, its expansion location, but that shouldn't matter) and then 
translates line numbers according to the `#line` directives in the file.
So the question is: why is `FileEntry` null for original location, but not null 
for `PresumedLoc`?

Sorry for confusion, if any, I just want to understand to make sure we're 
looking at the right place to solve your original problem.

>> int func(int param1);
>>  int func(int param2);
>>  // param1 and param2 could both have the same USR, but different names.
>>  That might (or might not) be surprising.
> 
> I agree here, they should have the same USR.

Let's get more opinions on this, I'm not 100% certain about it myself :-)

@arphaman, @bkramer, @hokein, @ioeric, @sammccall, should parameters of 
**different declarations** for the **same function overload** have the same or 
different USRs? WDYT?


Repository:
  rC Clang

https://reviews.llvm.org/D42966



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


[PATCH] D45532: [StaticAnalyzer] Checker to find uninitialized fields after a constructor call

2018-04-26 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus marked 3 inline comments as done.
Szelethus added a comment.

By the way, thank you all for taking the time to review my code!




Comment at: lib/StaticAnalyzer/Checkers/CtorUninitializedMemberChecker.cpp:306
+
+  const RecordDecl *RD =
+  R->getValueType()->getAs()->getDecl()->getDefinition();

a.sidorin wrote:
> What will happen if we analyze a member which is a pointer to a structure 
> type and the structure is of incomplete type?
For that field `isPointerOrReferenceUninit` will be called. If it happens not 
to be null, unknown or undef, the CSA core will construct a symbolic region for 
it, and the checker always assumes that symbolic regions are initialized, 
meaning that we'll never call `isNonUnionUninit` for a field of incomplete type.

However, I did not cover this with tests, thanks for pointing it out!



Comment at: test/Analysis/ctor-uninitialized-member.cpp:554
+
+void f23p15() {
+  void *vptr = malloc(sizeof(int));

a.sidorin wrote:
> Could you please explain what is the logic of test naming?
The test files follow the strict structure that for each test case we'll define 
a structure type and then call its constructor(s) in a function right after it 
(functions are used to avoid zero initializations).

To be honest, there is no real logic behind the naming of the functions, it is 
only to keep the ODR. I used numbers in an increasing order, however I later 
added there cases, so in between `f23` and `f24` I used `f23p5` and so on.

I figured that the strict structure of the test files would avoid confusion. Do 
you find it distracting?


https://reviews.llvm.org/D45532



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


r330946 - Add getDeserializationListener to ASTReader

2018-04-26 Thread Yuka Takahashi via cfe-commits
Author: yamaguchi
Date: Thu Apr 26 08:09:13 2018
New Revision: 330946

URL: http://llvm.org/viewvc/llvm-project?rev=330946&view=rev
Log:
Add getDeserializationListener to ASTReader

Summary:
We need to know if ASTReader already has a DeserializationListner or
not, and this also helps to create a multiplexing deserialization
listener if there is one already attached.

Reviewers: v.g.vassilev, rsmith, dblaikie, thakis

Subscribers: cfe-commits

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

Modified:
cfe/trunk/include/clang/Serialization/ASTReader.h

Modified: cfe/trunk/include/clang/Serialization/ASTReader.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTReader.h?rev=330946&r1=330945&r2=330946&view=diff
==
--- cfe/trunk/include/clang/Serialization/ASTReader.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTReader.h Thu Apr 26 08:09:13 2018
@@ -1599,6 +1599,11 @@ public:
   void setDeserializationListener(ASTDeserializationListener *Listener,
   bool TakeOwnership = false);
 
+  /// \brief Get the AST deserialization listener.
+  ASTDeserializationListener *getDeserializationListener() {
+return DeserializationListener;
+  }
+
   /// \brief Determine whether this AST reader has a global index.
   bool hasGlobalIndex() const { return (bool)GlobalIndex; }
 


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


[PATCH] D45921: Add getDeserializationListener to ASTReader

2018-04-26 Thread Yuka Takahashi via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL330946: Add getDeserializationListener to ASTReader 
(authored by yamaguchi, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D45921?vs=143441&id=144124#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D45921

Files:
  cfe/trunk/include/clang/Serialization/ASTReader.h


Index: cfe/trunk/include/clang/Serialization/ASTReader.h
===
--- cfe/trunk/include/clang/Serialization/ASTReader.h
+++ cfe/trunk/include/clang/Serialization/ASTReader.h
@@ -1599,6 +1599,11 @@
   void setDeserializationListener(ASTDeserializationListener *Listener,
   bool TakeOwnership = false);
 
+  /// \brief Get the AST deserialization listener.
+  ASTDeserializationListener *getDeserializationListener() {
+return DeserializationListener;
+  }
+
   /// \brief Determine whether this AST reader has a global index.
   bool hasGlobalIndex() const { return (bool)GlobalIndex; }
 


Index: cfe/trunk/include/clang/Serialization/ASTReader.h
===
--- cfe/trunk/include/clang/Serialization/ASTReader.h
+++ cfe/trunk/include/clang/Serialization/ASTReader.h
@@ -1599,6 +1599,11 @@
   void setDeserializationListener(ASTDeserializationListener *Listener,
   bool TakeOwnership = false);
 
+  /// \brief Get the AST deserialization listener.
+  ASTDeserializationListener *getDeserializationListener() {
+return DeserializationListener;
+  }
+
   /// \brief Determine whether this AST reader has a global index.
   bool hasGlobalIndex() const { return (bool)GlobalIndex; }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46022: [OpenCL] Restrict various keywords in OpenCL C++ mode

2018-04-26 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: include/clang/Basic/TokenKinds.def:255
+//   KEYNOOPENCL  - This is a keyword that is not supported in OpenCL C
+//  nor in OpenCL C++.
 //   KEYALTIVEC - This is a keyword in AltiVec

svenvh wrote:
> rjmccall wrote:
> > `KEYNOOPENCL` is dead now, I think.
> There are still some other uses of `KEYNOOPENCL` (already there before this 
> patch).
Oh, I see.



Comment at: lib/Parse/ParseStmtAsm.cpp:696
+return StmtError();
+  }
+

You might consider parsing the statement normally and then just diagnosing 
after the fact, maybe in Sema.  You'd have to add the check in a couple 
different places, though.



Comment at: lib/Sema/DeclSpec.cpp:621
+// OpenCL C++ 1.0 s2.9: the thread_local storage qualifier is not
+// supported.
+case TSCS_thread_local:

svenvh wrote:
> rjmccall wrote:
> > Do you really care about the spelling of the specifier?  Presumably 
> > `__thread` (the GNU extension) and `_Thread_local` (the C11 feature) are 
> > unsupported; where are those diagnosed?
> Fair enough, I have updated the patch to just reject any thread qualifier 
> here.
I meant it as a question, but I take it from this response that we don't 
actually diagnose these.

It might make more sense to diagnose this in `Sema::ActOnVariableDeclarator`, 
where we're already doing some checking about whether e.g. the target supports 
the feature.



Comment at: lib/Sema/SemaStmt.cpp:2791
+ << "goto");
+  }
+

Is this restriction really OpenCL C++-specific?  I mean, if that's what the 
language spec says, that's what it says, but I don't know what about OpenCL C++ 
would make `goto` unsupportable when it's supportable in ordinary OpenCL.

You should also add this check to ActOnIndirectGotoStmt.


https://reviews.llvm.org/D46022



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


[PATCH] D44387: [x86] Introduce the pconfig/encl[u|s|v] intrinsics

2018-04-26 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

I didn't see an answer to the inline assembly question.




Comment at: lib/Headers/pconfigintrin.h:31
+
+#define MKTME_KEY_PROGRAM 0x0001
+

craig.topper wrote:
> This doesn't match the name used by gcc. It also needs to start with 
> underscores since all names without underscores belong to user code.
Gcc's constant is called __PCONFIG_KEY_PROGRAM from what I see in their 
repository


https://reviews.llvm.org/D44387



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


Re: [PATCH] D42966: Fix USR generation in the presence of #line directives or linemarkes

2018-04-26 Thread Mikhail Ramalho via cfe-commits
Hi,


> Or is the that whenever there's a `#line` directive we get into a
> "virtual" file that's not registered in the `SourceManager`?
>
>
The virtual file is actually registered in the SourceManager but the
FileEntry for it is NULL (USRGeneration.cpp:33), which forces printLoc to
return true (USRGeneration.cpp:38) and the USR is not generated.

I believe the USR gen for params should have follow the functionDecl
convention. I'm reworking the patch now.


> int func(int param1);
> int func(int param2);
> // param1 and param2 could both have the same USR, but different names.
> That might (or might not) be surprising.
>

I agree here, they should have the same USR.


-- 

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


[PATCH] D45720: [X86] Lowering PACK*S (pack with saturation) intrinsics to native IR (clang side)

2018-04-26 Thread Mikhail Dvoretckii via Phabricator via cfe-commits
mike.dvoretsky updated this revision to Diff 144126.
mike.dvoretsky added a comment.

Changed the shuffle mask emission code to match https://reviews.llvm.org/D45721.


https://reviews.llvm.org/D45720

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/avx2-builtins.c
  clang/test/CodeGen/avx512bw-builtins.c
  clang/test/CodeGen/avx512vlbw-builtins.c
  clang/test/CodeGen/sse2-builtins.c
  clang/test/CodeGen/sse41-builtins.c

Index: clang/test/CodeGen/sse41-builtins.c
===
--- clang/test/CodeGen/sse41-builtins.c
+++ clang/test/CodeGen/sse41-builtins.c
@@ -328,7 +328,12 @@
 
 __m128i test_mm_packus_epi32(__m128i x, __m128i y) {
   // CHECK-LABEL: test_mm_packus_epi32
-  // CHECK: call <8 x i16> @llvm.x86.sse41.packusdw(<4 x i32> %{{.*}}, <4 x i32> %{{.*}})
+  // CHECK: %{{.*}} = shufflevector <4 x i32> %{{.*}}, <4 x i32> %{{.*}}, <8 x i32> 
+  // CHECK: %{{.*}} = icmp slt <8 x i32> %{{.*}}, 
+  // CHECK: %{{.*}} = select <8 x i1> %{{.*}}, <8 x i32> %{{.*}}, <8 x i32> 
+  // CHECK: %{{.*}} = icmp sgt <8 x i32> %{{.*}}, zeroinitializer
+  // CHECK: %{{.*}} = select <8 x i1> %{{.*}}, <8 x i32> %{{.*}}, <8 x i32> zeroinitializer
+  // CHECK: %{{.*}} = trunc <8 x i32> %{{.*}} to <8 x i16>
   return _mm_packus_epi32(x, y);
 }
 
Index: clang/test/CodeGen/sse2-builtins.c
===
--- clang/test/CodeGen/sse2-builtins.c
+++ clang/test/CodeGen/sse2-builtins.c
@@ -869,19 +869,34 @@
 
 __m128i test_mm_packs_epi16(__m128i A, __m128i B) {
   // CHECK-LABEL: test_mm_packs_epi16
-  // CHECK: call <16 x i8> @llvm.x86.sse2.packsswb.128(<8 x i16> %{{.*}}, <8 x i16> %{{.*}})
+  // CHECK: %{{.*}} = shufflevector <8 x i16> %{{.*}}, <8 x i16> %{{.*}}, <16 x i32> 
+  // CHECK: %{{.*}} = icmp slt <16 x i16> %{{.*}}, 
+  // CHECK: %{{.*}} = select <16 x i1> %{{.*}}, <16 x i16> %{{.*}}, <16 x i16> 
+  // CHECK: %{{.*}} = icmp sgt <16 x i16> %{{.*}}, 
+  // CHECK: %{{.*}} = select <16 x i1> %{{.*}}, <16 x i16> %{{.*}}, <16 x i16> 
+  // CHECK: %{{.*}} = trunc <16 x i16> %{{.*}} to <16 x i8>
   return _mm_packs_epi16(A, B);
 }
 
 __m128i test_mm_packs_epi32(__m128i A, __m128i B) {
   // CHECK-LABEL: test_mm_packs_epi32
-  // CHECK: call <8 x i16> @llvm.x86.sse2.packssdw.128(<4 x i32> %{{.*}}, <4 x i32> %{{.*}})
+  // CHECK: %{{.*}} = shufflevector <4 x i32> %{{.*}}, <4 x i32> %{{.*}}, <8 x i32> 
+  // CHECK: %{{.*}} = icmp slt <8 x i32> %{{.*}}, 
+  // CHECK: %{{.*}} = select <8 x i1> %{{.*}}, <8 x i32> %{{.*}}, <8 x i32> 
+  // CHECK: %{{.*}} = icmp sgt <8 x i32> %{{.*}}, 
+  // CHECK: %{{.*}} = select <8 x i1> %{{.*}}, <8 x i32> %{{.*}}, <8 x i32> 
+  // CHECK: %{{.*}} = trunc <8 x i32> %{{.*}} to <8 x i16>
   return _mm_packs_epi32(A, B);
 }
 
 __m128i test_mm_packus_epi16(__m128i A, __m128i B) {
   // CHECK-LABEL: test_mm_packus_epi16
-  // CHECK: call <16 x i8> @llvm.x86.sse2.packuswb.128(<8 x i16> %{{.*}}, <8 x i16> %{{.*}})
+  // CHECK: %{{.*}} = shufflevector <8 x i16> %{{.*}}, <8 x i16> %{{.*}}, <16 x i32> 
+  // CHECK: %{{.*}} = icmp slt <16 x i16> %{{.*}}, 
+  // CHECK: %{{.*}} = select <16 x i1> %{{.*}}, <16 x i16> %{{.*}}, <16 x i16> 
+  // CHECK: %{{.*}} = icmp sgt <16 x i16> %{{.*}}, zeroinitializer
+  // CHECK: %{{.*}} = select <16 x i1> %{{.*}}, <16 x i16> %{{.*}}, <16 x i16> zeroinitializer
+  // CHECK: %{{.*}} = trunc <16 x i16> %{{.*}} to <16 x i8>
   return _mm_packus_epi16(A, B);
 }
 
Index: clang/test/CodeGen/avx512vlbw-builtins.c
===
--- clang/test/CodeGen/avx512vlbw-builtins.c
+++ clang/test/CodeGen/avx512vlbw-builtins.c
@@ -970,105 +970,185 @@
 
 __m128i test_mm_maskz_packs_epi32(__mmask8 __M, __m128i __A, __m128i __B) {
   // CHECK-LABEL: @test_mm_maskz_packs_epi32
-  // CHECK: @llvm.x86.sse2.packssdw
+  // CHECK: %{{.*}} = shufflevector <4 x i32> %{{.*}}, <4 x i32> %{{.*}}, <8 x i32> 
+  // CHECK: %{{.*}} = icmp slt <8 x i32> %{{.*}}, 
+  // CHECK: %{{.*}} = select <8 x i1> %{{.*}}, <8 x i32> %{{.*}}, <8 x i32> 
+  // CHECK: %{{.*}} = icmp sgt <8 x i32> %{{.*}}, 
+  // CHECK: %{{.*}} = select <8 x i1> %{{.*}}, <8 x i32> %{{.*}}, <8 x i32> 
+  // CHECK: %{{.*}} = trunc <8 x i32> %{{.*}} to <8 x i16>
   // CHECK: select <8 x i1> %{{.*}}, <8 x i16> %{{.*}}, <8 x i16> %{{.*}}
   return _mm_maskz_packs_epi32(__M,__A,__B); 
 }
 __m128i test_mm_mask_packs_epi32(__m128i __W, __mmask16 __M, __m128i __A,  __m128i __B) {
   // CHECK-LABEL: @test_mm_mask_packs_epi32
-  // CHECK: @llvm.x86.sse2.packssdw
+  // CHECK: %{{.*}} = shufflevector <4 x i32> %{{.*}}, <4 x i32> %{{.*}}, <8 x i32> 
+  // CHECK: %{{.*}} = icmp slt <8 x i32> %{{.*}}, 
+  // CHECK: %{{.*}} = select <8 x i1> %{{.*}}, <8 x i32> %{{.*}}, <8 x i32> 
+  // CHECK: %{{.*}} = icmp sgt <8 x i32> %{{.*}}, 
+  // CHECK: %{{.*}} = select <8 x i1> %{{.*}}, <8 x i32> %{{.*}}, <8 x i32> 
+  // CHECK: %{{.*}} = trunc <8 x i32> %{{.*}} to <8 x i16>
   // CHECK: select 

[PATCH] D46081: [analyzer] Expand conversion check to check more expressions for overflow and underflow

2018-04-26 Thread Paul Fultz II via Phabricator via cfe-commits
pfultz2 added a comment.

So moving to core will require explicit casts in some of the tests, especially 
for things like: `memcpy(a262.s1, input, -1)`. Or this could be moved to 
another section instead of core. In https://reviews.llvm.org/D45532 there is 
talk of adding a bugprone section. I think this would be good there.


Repository:
  rC Clang

https://reviews.llvm.org/D46081



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


[PATCH] D46052: GNUstep Objective-C ABI version 2

2018-04-26 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/CodeGen/CGObjCGNU.cpp:961
+  GV->setSection(Section);
+return GV;
+  }

I'd encourage you to use ConstantBuilder whenever you would want to use this.



Comment at: lib/CodeGen/CGObjCGNU.cpp:966
+
+std::string Str = SL->getString().str();
+CharUnits Align = CGM.getPointerAlign();

Why copy the string?  Also, you don't actually use it until later.



Comment at: lib/CodeGen/CGObjCGNU.cpp:977
+if ((CGM.getTarget().getPointerWidth(0) == 64) &&
+(SL->getLength() < 9) && !isNonASCII) {
+  // Tiny strings are (roughly):

Please hoist `SL->getLength()` into a variable.

Also, consider breaking this bit of code (maybe just building a `uint64_t`?) 
into a separate function.



Comment at: lib/CodeGen/CGObjCGNU.cpp:992
+  //   };
+  //   With a tag value of 4.
+  uint64_t str = 0;

It's weird to give a struct like this and have it only be right on a 
*big*-endian target.  You might also consider just using `uint64_t`.



Comment at: lib/CodeGen/CGObjCGNU.cpp:996
+  for (unsigned i=0 ; igetLength() ; i++)
+str |= ((uint64_t)SL->getCodeUnit(i)) << (57 - (i*7));
+  // Fill in the length

I think this might be clearer as `64 - 7 - (i*7)`.



Comment at: lib/CodeGen/CGObjCGNU.cpp:1039
+if (isNonASCII) {
+  unsigned NumBytes = Str.size();
+  SmallVector ToBuf(NumBytes + 1); // +1 for ending 
nulls.

This is a very misleading variable name.



Comment at: lib/CodeGen/CGObjCGNU.cpp:1040
+  unsigned NumBytes = Str.size();
+  SmallVector ToBuf(NumBytes + 1); // +1 for ending 
nulls.
+  const llvm::UTF8 *FromPtr = (const llvm::UTF8 *)Str.data();

You should leave a comment saying that it's safe to expand an N-code-unit UTF-8 
string into an N-code-unit UTF-16 buffer because UTF-16 never uses more code 
units than UTF-8.



Comment at: lib/CodeGen/CGObjCGNU.cpp:1077
+std::replace(StringName.begin(), StringName.end(),
+  '@', '\1');
+auto *ObjCStrGV =

Is `@` really the only illegal character in ELF symbol names?  Surely at least 
`\0` as well.  And your mangling will collide strings if they contain `\1`.

I think you should probably just have this use internal linkage (and a 
meaningless symbol name) for strings containing bad characters.



Comment at: lib/CodeGen/CGObjCGNU.cpp:1081
+ObjCStrGV->setSection(ConstantStringSection);
+ObjCStrGV->setLinkage(llvm::GlobalValue::ExternalLinkage);
+ObjCStrGV->setComdat(TheModule.getOrInsertComdat(StringName));

Surely this has to be `linkonce_odr`?



Comment at: lib/CodeGen/CGObjCGNU.cpp:1097
+ASTContext &Context = CGM.getContext();
+Fields.add(MakeConstantString(property->getNameAsString()));
+std::string TypeStr =

Field declaration comments, like you use elsewhere, would help here.  And 
something that includes the struct name that you're generating as well.



Comment at: lib/CodeGen/CGObjCGNU.cpp:1126
+auto MethodList = Builder.beginStruct();
+// int count;
+MethodList.addInt(IntTy, Methods.size());

Same comment here about adding a comment somewhere that mentions the struct 
name from the runtime header that you're generating.



Comment at: lib/CodeGen/CGObjCGNU.cpp:1196
+  case Qualifiers::OCL_None:
+  default:
+Flag = 0;

Please make this exhaustive, since you're just missing 
`Qualifiers::OCL_Autoreleasing` (which is illegal on an ivar, of course).



Comment at: lib/CodeGen/CGObjCGNU.cpp:1216
+  llvm::GlobalValue::ExternalLinkage, nullptr, Name);
+  GV->setAlignment(4);
+}

Why 4?



Comment at: lib/CodeGen/CGObjCGNU.cpp:1395
+auto *SelStart = GetSectionStart(SelSection);
+auto *SelEnd = GetSectionStop(SelSection);
+auto *ClsStart = GetSectionStart(ClsSection);

Maybe you can have a method that returns the start/end symbols as a pair?  It 
would cut down on the redundancy here a lot.


Repository:
  rC Clang

https://reviews.llvm.org/D46052



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


[PATCH] D45601: Warn on bool* to bool conversion

2018-04-26 Thread Aditya Kumar via Phabricator via cfe-commits
hiraditya abandoned this revision.
hiraditya added a comment.

It appears this warning may not be always useful because there will be false 
positives.


https://reviews.llvm.org/D45601



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


[libcxx] r330955 - Move old test into test/libcxx, and implement new version of test for ostreambuf_iterator::failed. Fixes PR#37245. Thanks to Billy O'Neill for the bug report.

2018-04-26 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Thu Apr 26 09:16:45 2018
New Revision: 330955

URL: http://llvm.org/viewvc/llvm-project?rev=330955&view=rev
Log:
Move old test into test/libcxx, and implement new version of test for 
ostreambuf_iterator::failed. Fixes PR#37245. Thanks to Billy O'Neill for the 
bug report.

Added:
libcxx/trunk/test/libcxx/iterators/failed.pass.cpp
  - copied, changed from r330716, 
libcxx/trunk/test/std/iterators/stream.iterators/ostreambuf.iterator/ostreambuf.iter.ops/failed.pass.cpp
Modified:

libcxx/trunk/test/std/iterators/stream.iterators/ostreambuf.iterator/ostreambuf.iter.ops/failed.pass.cpp

Copied: libcxx/trunk/test/libcxx/iterators/failed.pass.cpp (from r330716, 
libcxx/trunk/test/std/iterators/stream.iterators/ostreambuf.iterator/ostreambuf.iter.ops/failed.pass.cpp)
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/iterators/failed.pass.cpp?p2=libcxx/trunk/test/libcxx/iterators/failed.pass.cpp&p1=libcxx/trunk/test/std/iterators/stream.iterators/ostreambuf.iterator/ostreambuf.iter.ops/failed.pass.cpp&r1=330716&r2=330955&rev=330955&view=diff
==
--- 
libcxx/trunk/test/std/iterators/stream.iterators/ostreambuf.iterator/ostreambuf.iter.ops/failed.pass.cpp
 (original)
+++ libcxx/trunk/test/libcxx/iterators/failed.pass.cpp Thu Apr 26 09:16:45 2018
@@ -12,6 +12,8 @@
 // class ostreambuf_iterator
 
 // bool failed() const throw();
+//
+// Extension: constructing from NULL is UB; we just make it a failed 
iterator
 
 #include 
 #include 

Modified: 
libcxx/trunk/test/std/iterators/stream.iterators/ostreambuf.iterator/ostreambuf.iter.ops/failed.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/iterators/stream.iterators/ostreambuf.iterator/ostreambuf.iter.ops/failed.pass.cpp?rev=330955&r1=330954&r2=330955&view=diff
==
--- 
libcxx/trunk/test/std/iterators/stream.iterators/ostreambuf.iterator/ostreambuf.iter.ops/failed.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/iterators/stream.iterators/ostreambuf.iterator/ostreambuf.iter.ops/failed.pass.cpp
 Thu Apr 26 09:16:45 2018
@@ -17,14 +17,27 @@
 #include 
 #include 
 
+template  >
+struct my_streambuf : public std::basic_streambuf {
+   typedef typename std::basic_streambuf::int_type  int_type;
+   typedef typename std::basic_streambuf::char_type char_type;
+   
+   my_streambuf() {}
+   int_type sputc(char_type) { return Traits::eof(); }
+   };
+
 int main()
 {
 {
-std::ostreambuf_iterator i(nullptr);
+   my_streambuf buf;
+std::ostreambuf_iterator i(&buf);
+i = 'a';
 assert(i.failed());
 }
 {
-std::ostreambuf_iterator i(nullptr);
+   my_streambuf buf;
+std::ostreambuf_iterator i(&buf);
+i = L'a';
 assert(i.failed());
 }
 }


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


[PATCH] D46022: [OpenCL] Restrict various keywords in OpenCL C++ mode

2018-04-26 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh added inline comments.



Comment at: lib/Parse/ParseStmtAsm.cpp:696
+return StmtError();
+  }
+

rjmccall wrote:
> You might consider parsing the statement normally and then just diagnosing 
> after the fact, maybe in Sema.  You'd have to add the check in a couple 
> different places, though.
Precisely the reason why I did it in the parser, otherwise we'd have to 
duplicate the check in multiple places.



Comment at: lib/Sema/DeclSpec.cpp:621
+// OpenCL C++ 1.0 s2.9: the thread_local storage qualifier is not
+// supported.
+case TSCS_thread_local:

rjmccall wrote:
> svenvh wrote:
> > rjmccall wrote:
> > > Do you really care about the spelling of the specifier?  Presumably 
> > > `__thread` (the GNU extension) and `_Thread_local` (the C11 feature) are 
> > > unsupported; where are those diagnosed?
> > Fair enough, I have updated the patch to just reject any thread qualifier 
> > here.
> I meant it as a question, but I take it from this response that we don't 
> actually diagnose these.
> 
> It might make more sense to diagnose this in `Sema::ActOnVariableDeclarator`, 
> where we're already doing some checking about whether e.g. the target 
> supports the feature.
We do actually diagnose the others in `Sema::ActOnVariableDeclarator` 
("thread-local storage is not supported for the current target").  But your 
question made me realize there is no real need to differentiate here for the 
OpenCL C++ case.



Comment at: lib/Sema/SemaStmt.cpp:2791
+ << "goto");
+  }
+

rjmccall wrote:
> Is this restriction really OpenCL C++-specific?  I mean, if that's what the 
> language spec says, that's what it says, but I don't know what about OpenCL 
> C++ would make `goto` unsupportable when it's supportable in ordinary OpenCL.
> 
> You should also add this check to ActOnIndirectGotoStmt.
Yes (oddly enough).  The OpenCL C++ 1.0 spec explicitly mentions `goto` in the 
Restrictions section on page 51.  The OpenCL C 1.1 / 2.0 specs ("ordinary 
OpenCL") do not restrict goto.

I'll add the check for indirect goto statements.


https://reviews.llvm.org/D46022



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


[PATCH] D46022: [OpenCL] Restrict various keywords in OpenCL C++ mode

2018-04-26 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh updated this revision to Diff 144138.
svenvh added a comment.

Reject goto in `Sema::ActOnIndirectGotoStmt` too, and add a test for indirect 
goto.


https://reviews.llvm.org/D46022

Files:
  include/clang/Basic/DiagnosticCommonKinds.td
  include/clang/Basic/DiagnosticParseKinds.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/TokenKinds.def
  include/clang/Sema/DeclSpec.h
  lib/Basic/IdentifierTable.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Parse/ParseDecl.cpp
  lib/Parse/ParseStmtAsm.cpp
  lib/Sema/DeclSpec.cpp
  lib/Sema/SemaCast.cpp
  lib/Sema/SemaExprCXX.cpp
  lib/Sema/SemaStmt.cpp
  test/Parser/opencl-cl20.cl
  test/Parser/opencl-cxx-keywords.cl
  test/Parser/opencl-storage-class.cl
  test/SemaOpenCL/storageclass.cl
  test/SemaOpenCLCXX/restricted.cl

Index: test/SemaOpenCLCXX/restricted.cl
===
--- /dev/null
+++ test/SemaOpenCLCXX/restricted.cl
@@ -0,0 +1,77 @@
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=c++ -pedantic -verify -fsyntax-only
+
+// This test checks that various C/C++/OpenCL C constructs are not available in
+// OpenCL C++, according to OpenCL C++ 1.0 Specification Section 2.9.
+
+// Test that typeid is not available in OpenCL C++.
+namespace std {
+  // Provide a dummy std::type_info so that we can use typeid.
+  class type_info {
+int a;
+  };
+}
+__constant std::type_info int_ti = typeid(int);
+// expected-error@-1 {{'typeid' is not supported in OpenCL C++}}
+
+// Test that dynamic_cast is not available in OpenCL C++.
+class A {
+public:
+  int a;
+};
+
+class B : public A {
+  int b;
+};
+
+B *test_dynamic_cast(B *p) {
+  return dynamic_cast(p);
+  // expected-error@-1 {{'dynamic_cast' is not supported in OpenCL C++}}
+}
+
+// Test storage class qualifiers.
+__constant _Thread_local int a = 1;
+// expected-error@-1 {{OpenCL C++ version 1.0 does not support the '_Thread_local' storage class specifier}}
+__constant __thread int b = 2;
+// expected-error@-1 {{OpenCL C++ version 1.0 does not support the '__thread' storage class specifier}}
+kernel void test_storage_classes() {
+  register int x;
+  // expected-error@-1 {{OpenCL C++ version 1.0 does not support the 'register' storage class specifier}}
+  thread_local int y;
+  // expected-error@-1 {{OpenCL C++ version 1.0 does not support the 'thread_local' storage class specifier}}
+}
+
+// Test that access qualifiers are reserved keywords.
+kernel void test_access_qualifiers() {
+  int read_only;
+  // expected-error@-1 {{'read_only' is a reserved keyword in OpenCL C++}}
+  // expected-warning@-2 {{declaration does not declare anything}}
+  int __read_only;
+  // expected-error@-1 {{'__read_only' is a reserved keyword in OpenCL C++}}
+  // expected-warning@-2 {{declaration does not declare anything}}
+  int write_only;
+  // expected-error@-1 {{'write_only' is a reserved keyword in OpenCL C++}}
+  // expected-warning@-2 {{declaration does not declare anything}}
+  int __write_only;
+  // expected-error@-1 {{'__write_only' is a reserved keyword in OpenCL C++}}
+  // expected-warning@-2 {{declaration does not declare anything}}
+  int read_write;
+  // expected-error@-1 {{'read_write' is a reserved keyword in OpenCL C++}}
+  // expected-warning@-2 {{declaration does not declare anything}}
+  int __read_write;
+  // expected-error@-1 {{'__read_write' is a reserved keyword in OpenCL C++}}
+  // expected-warning@-2 {{declaration does not declare anything}}
+}
+
+// Test other keywords that are not available in OpenCL C++.
+kernel void test_misc() {
+  goto label;
+  // expected-error@-1 {{'goto' is not supported in OpenCL C++}}
+  goto *&&label;
+  // expected-error@-1 {{'goto' is not supported in OpenCL C++}}
+  // expected-warning@-2 {{use of GNU indirect-goto extension}}
+  // expected-warning@-3 {{use of GNU address-of-label extension}}
+label:
+  asm("");
+  // expected-error@-1 {{'asm' is not supported in OpenCL C++}}
+  // expected-warning@-2 {{expression result unused}}
+}
Index: test/SemaOpenCL/storageclass.cl
===
--- test/SemaOpenCL/storageclass.cl
+++ test/SemaOpenCL/storageclass.cl
@@ -10,14 +10,14 @@
 static global float g_global_static_var = 0;   // expected-error {{program scope variable must reside in constant address space}}
 static local float g_local_static_var = 0; // expected-error {{program scope variable must reside in constant address space}}
 static private float g_private_static_var = 0; // expected-error {{program scope variable must reside in constant address space}}
-static generic float g_generic_static_var = 0; // expected-error{{OpenCL version 1.2 does not support the 'generic' type qualifier}} // expected-error {{program scope variable must reside in constant address space}}
+static generic float g_generic_static_var = 0; // expected-error{{OpenCL C version 1.2 does not support the 'generic' type qualifier}} // expected-error 

[PATCH] D46131: Add Microsoft Mangling for OpenCL Half Type

2018-04-26 Thread Vince Bridgers via Phabricator via cfe-commits
vbridgers created this revision.
vbridgers added reviewers: rnk, Anastasia, erichkeane.
vbridgers added a project: clang.
Herald added subscribers: cfe-commits, yaxunl.

Half-type mangling is accomplished following the method introduced by Erich 
Keane for mangling _Float16. Updated the half.cl LIT test to cover this 
particular case.


Repository:
  rC Clang

https://reviews.llvm.org/D46131

Files:
  lib/AST/MicrosoftMangle.cpp
  test/CodeGenOpenCL/half.cl


Index: test/CodeGenOpenCL/half.cl
===
--- test/CodeGenOpenCL/half.cl
+++ test/CodeGenOpenCL/half.cl
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown | FileCheck 
%s
+// RUN: %clang_cc1 %s -emit-llvm -o - -triple x86_64-pc-win32 | FileCheck %s
 
 #pragma OPENCL EXTENSION cl_khr_fp16 : enable
 
Index: lib/AST/MicrosoftMangle.cpp
===
--- lib/AST/MicrosoftMangle.cpp
+++ lib/AST/MicrosoftMangle.cpp
@@ -1922,8 +1922,11 @@
 mangleArtificalTagType(TTK_Struct, "_Float16", {"__clang"});
 break;
 
-  case BuiltinType::Float128:
-  case BuiltinType::Half: {
+  case BuiltinType::Half:
+mangleArtificalTagType(TTK_Struct, "_Half", {"__clang"});
+break;
+
+  case BuiltinType::Float128: {
 DiagnosticsEngine &Diags = Context.getDiags();
 unsigned DiagID = Diags.getCustomDiagID(
 DiagnosticsEngine::Error, "cannot mangle this built-in %0 type yet");


Index: test/CodeGenOpenCL/half.cl
===
--- test/CodeGenOpenCL/half.cl
+++ test/CodeGenOpenCL/half.cl
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown | FileCheck %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -triple x86_64-pc-win32 | FileCheck %s
 
 #pragma OPENCL EXTENSION cl_khr_fp16 : enable
 
Index: lib/AST/MicrosoftMangle.cpp
===
--- lib/AST/MicrosoftMangle.cpp
+++ lib/AST/MicrosoftMangle.cpp
@@ -1922,8 +1922,11 @@
 mangleArtificalTagType(TTK_Struct, "_Float16", {"__clang"});
 break;
 
-  case BuiltinType::Float128:
-  case BuiltinType::Half: {
+  case BuiltinType::Half:
+mangleArtificalTagType(TTK_Struct, "_Half", {"__clang"});
+break;
+
+  case BuiltinType::Float128: {
 DiagnosticsEngine &Diags = Context.getDiags();
 unsigned DiagID = Diags.getCustomDiagID(
 DiagnosticsEngine::Error, "cannot mangle this built-in %0 type yet");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46132: [X86] Make __builtin_ia32_readeflags_u32 and __builtin_ia32_writeeflags_u32 only available on 32-bit targets.

2018-04-26 Thread Craig Topper via Phabricator via cfe-commits
craig.topper created this revision.
craig.topper added reviewers: rnk, echristo, chandlerc.

These builtins can't be handled by the backend on 64-bit targets. So error up 
front instead of throwing an isel error.

Fixes PR37225


Repository:
  rC Clang

https://reviews.llvm.org/D46132

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaChecking.cpp
  test/Sema/builtins-x86.c


Index: test/Sema/builtins-x86.c
===
--- test/Sema/builtins-x86.c
+++ test/Sema/builtins-x86.c
@@ -16,6 +16,11 @@
 typedef unsigned short __mmask16;
 typedef unsigned int __mmask32;
 
+void call_x86_32_builtins(void) {
+  (void)__builtin_ia32_readeflags_u32(); // 
expected-error{{this builtin is only available on 32-bit targets}}
+  (void)__builtin_ia32_writeeflags_u32(4);   // 
expected-error{{this builtin is only available on 32-bit targets}}
+}
+
 __m128 test__builtin_ia32_cmpps(__m128 __a, __m128 __b) {
   __builtin_ia32_cmpps(__a, __b, 32); // expected-error {{argument should be a 
value from 0 to 31}}
 }
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -2309,13 +2309,30 @@
 << Arg->getSourceRange();
 }
 
+static bool isX86_32Builtin(unsigned BuiltinID) {
+  // These builtins only work on x86-32 targets.
+  switch (BuiltinID) {
+  case X86::BI__builtin_ia32_readeflags_u32:
+  case X86::BI__builtin_ia32_writeeflags_u32:
+return true;
+  }
+
+  return false;
+}
+
 bool Sema::CheckX86BuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
   if (BuiltinID == X86::BI__builtin_cpu_supports)
 return SemaBuiltinCpuSupports(*this, TheCall);
 
   if (BuiltinID == X86::BI__builtin_cpu_is)
 return SemaBuiltinCpuIs(*this, TheCall);
 
+  // Check for 32-bit only builtins on a 64-bit target.
+  const llvm::Triple &TT = Context.getTargetInfo().getTriple();
+  if (TT.getArch() != llvm::Triple::x86 && isX86_32Builtin(BuiltinID))
+return Diag(TheCall->getCallee()->getLocStart(),
+diag::err_32_bit_builtin_64_bit_tgt);
+
   // If the intrinsic has rounding or SAE make sure its valid.
   if (CheckX86BuiltinRoundingOrSAE(BuiltinID, TheCall))
 return true;
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -8251,6 +8251,8 @@
   "invalid transaction abort code">;
 def err_64_bit_builtin_32_bit_tgt : Error<
   "this builtin is only available on 64-bit targets">;
+def err_32_bit_builtin_64_bit_tgt : Error<
+  "this builtin is only available on 32-bit targets">;
 def err_builtin_x64_aarch64_only : Error<
   "this builtin is only available on x86-64 and aarch64 targets">;
 def err_ppc_builtin_only_on_pwr7 : Error<


Index: test/Sema/builtins-x86.c
===
--- test/Sema/builtins-x86.c
+++ test/Sema/builtins-x86.c
@@ -16,6 +16,11 @@
 typedef unsigned short __mmask16;
 typedef unsigned int __mmask32;
 
+void call_x86_32_builtins(void) {
+  (void)__builtin_ia32_readeflags_u32(); // expected-error{{this builtin is only available on 32-bit targets}}
+  (void)__builtin_ia32_writeeflags_u32(4);   // expected-error{{this builtin is only available on 32-bit targets}}
+}
+
 __m128 test__builtin_ia32_cmpps(__m128 __a, __m128 __b) {
   __builtin_ia32_cmpps(__a, __b, 32); // expected-error {{argument should be a value from 0 to 31}}
 }
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -2309,13 +2309,30 @@
 << Arg->getSourceRange();
 }
 
+static bool isX86_32Builtin(unsigned BuiltinID) {
+  // These builtins only work on x86-32 targets.
+  switch (BuiltinID) {
+  case X86::BI__builtin_ia32_readeflags_u32:
+  case X86::BI__builtin_ia32_writeeflags_u32:
+return true;
+  }
+
+  return false;
+}
+
 bool Sema::CheckX86BuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
   if (BuiltinID == X86::BI__builtin_cpu_supports)
 return SemaBuiltinCpuSupports(*this, TheCall);
 
   if (BuiltinID == X86::BI__builtin_cpu_is)
 return SemaBuiltinCpuIs(*this, TheCall);
 
+  // Check for 32-bit only builtins on a 64-bit target.
+  const llvm::Triple &TT = Context.getTargetInfo().getTriple();
+  if (TT.getArch() != llvm::Triple::x86 && isX86_32Builtin(BuiltinID))
+return Diag(TheCall->getCallee()->getLocStart(),
+diag::err_32_bit_builtin_64_bit_tgt);
+
   // If the intrinsic has rounding or SAE make sure its valid.
   if (CheckX86BuiltinRoundingOrSAE(BuiltinID, TheCall))
 return true;
Index: include/clang/Basic/DiagnosticSemaKinds.td

[PATCH] D46022: [OpenCL] Restrict various keywords in OpenCL C++ mode

2018-04-26 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/Parse/ParseStmtAsm.cpp:696
+return StmtError();
+  }
+

svenvh wrote:
> rjmccall wrote:
> > You might consider parsing the statement normally and then just diagnosing 
> > after the fact, maybe in Sema.  You'd have to add the check in a couple 
> > different places, though.
> Precisely the reason why I did it in the parser, otherwise we'd have to 
> duplicate the check in multiple places.
The downside of this is that the parser recovery is probably very bad.  But 
since this is asm, it's not likely to matter too much.

...is this *also* really only an OpenCL C++ restriction?  Maybe we should read 
this one as a general restriction that happens to have been overlooked in the 
OpenCL C spec.



Comment at: lib/Sema/DeclSpec.cpp:621
+// OpenCL C++ 1.0 s2.9: the thread_local storage qualifier is not
+// supported.
+case TSCS_thread_local:

svenvh wrote:
> rjmccall wrote:
> > svenvh wrote:
> > > rjmccall wrote:
> > > > Do you really care about the spelling of the specifier?  Presumably 
> > > > `__thread` (the GNU extension) and `_Thread_local` (the C11 feature) 
> > > > are unsupported; where are those diagnosed?
> > > Fair enough, I have updated the patch to just reject any thread qualifier 
> > > here.
> > I meant it as a question, but I take it from this response that we don't 
> > actually diagnose these.
> > 
> > It might make more sense to diagnose this in 
> > `Sema::ActOnVariableDeclarator`, where we're already doing some checking 
> > about whether e.g. the target supports the feature.
> We do actually diagnose the others in `Sema::ActOnVariableDeclarator` 
> ("thread-local storage is not supported for the current target").  But your 
> question made me realize there is no real need to differentiate here for the 
> OpenCL C++ case.
Okay.  So we can remove this code, then.


https://reviews.llvm.org/D46022



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


[PATCH] D46024: [clang-format] Add SpaceBeforeCpp11BracedList option.

2018-04-26 Thread Ross Kirsling via Phabricator via cfe-commits
rkirsling added a comment.

In https://reviews.llvm.org/D46024#1079390, @klimek wrote:

> Is this written down somewhere? https://webkit.org/code-style-guidelines/ 
> doesn't seem to mention it.


I agree that it really ought to be mentioned there—I'll try to bring that up 
with the original authors of that document.

It is enforced by the style checker (though the rule is not specific to braced 
initialization):
https://github.com/WebKit/webkit/blob/master/Tools/Scripts/webkitpy/style/checkers/cpp.py#L1972-L1978

Statistically speaking, when grepping the Source directory (excluding 
Source/ThirdParty) for *.h and *.cpp files:

- with space (`\w+\s\{.*\};`) has 11544 matches across 2744 files
- without space (`\w+\{.*\};`) has 29 matches across 10 files


Repository:
  rC Clang

https://reviews.llvm.org/D46024



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


[PATCH] D46022: [OpenCL] Restrict various keywords in OpenCL C++ mode

2018-04-26 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh added inline comments.



Comment at: lib/Parse/ParseStmtAsm.cpp:696
+return StmtError();
+  }
+

rjmccall wrote:
> svenvh wrote:
> > rjmccall wrote:
> > > You might consider parsing the statement normally and then just 
> > > diagnosing after the fact, maybe in Sema.  You'd have to add the check in 
> > > a couple different places, though.
> > Precisely the reason why I did it in the parser, otherwise we'd have to 
> > duplicate the check in multiple places.
> The downside of this is that the parser recovery is probably very bad.  But 
> since this is asm, it's not likely to matter too much.
> 
> ...is this *also* really only an OpenCL C++ restriction?  Maybe we should 
> read this one as a general restriction that happens to have been overlooked 
> in the OpenCL C spec.
Yes, `asm` is only explicitly restricted in OpenCL C++.  Not sure if it's safe 
to assume `asm` has been overlooked for OpenCL C though, it's not explicitly 
forbidden so people may be using it.



Comment at: lib/Sema/DeclSpec.cpp:621
+// OpenCL C++ 1.0 s2.9: the thread_local storage qualifier is not
+// supported.
+case TSCS_thread_local:

rjmccall wrote:
> svenvh wrote:
> > rjmccall wrote:
> > > svenvh wrote:
> > > > rjmccall wrote:
> > > > > Do you really care about the spelling of the specifier?  Presumably 
> > > > > `__thread` (the GNU extension) and `_Thread_local` (the C11 feature) 
> > > > > are unsupported; where are those diagnosed?
> > > > Fair enough, I have updated the patch to just reject any thread 
> > > > qualifier here.
> > > I meant it as a question, but I take it from this response that we don't 
> > > actually diagnose these.
> > > 
> > > It might make more sense to diagnose this in 
> > > `Sema::ActOnVariableDeclarator`, where we're already doing some checking 
> > > about whether e.g. the target supports the feature.
> > We do actually diagnose the others in `Sema::ActOnVariableDeclarator` 
> > ("thread-local storage is not supported for the current target").  But your 
> > question made me realize there is no real need to differentiate here for 
> > the OpenCL C++ case.
> Okay.  So we can remove this code, then.
Sorry if my previous comment was ambiguous: I meant here we now reject *any* 
thread storage class specifier for OpenCL C++, not just the `thread_local` 
spelling (my original patch was only rejecting `TSCS_thread_local`).


https://reviews.llvm.org/D46022



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


[PATCH] D46049: [OpenCL] Add constant address space to __func__ in AST

2018-04-26 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia updated this revision to Diff 144154.
Anastasia added a comment.

- Renamed test;
- Reformatted;
- Added constant in StringLiteral creation.


https://reviews.llvm.org/D46049

Files:
  lib/AST/Expr.cpp
  lib/Sema/SemaExpr.cpp
  test/SemaOpenCL/predefined-expr.cl


Index: test/SemaOpenCL/predefined-expr.cl
===
--- /dev/null
+++ test/SemaOpenCL/predefined-expr.cl
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 %s -verify
+
+void f() {
+  char *f1 = __func__;  //expected-error{{initializing 'char *' with 
an expression of type 'const __constant char *' changes address space of 
pointer}}
+  constant char *f2 = __func__; //expected-warning{{initializing '__constant 
char *' with an expression of type 'const __constant char [2]' discards 
qualifiers}}
+  constant const char *f3 = __func__;
+}
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -3052,6 +3052,8 @@
  /*Pascal*/ false, ResTy, Loc);
 } else {
   ResTy = Context.CharTy.withConst();
+  if (LangOpts.OpenCL)
+ResTy = Context.getAddrSpaceQualType(ResTy, LangAS::opencl_constant);
   ResTy = Context.getConstantArrayType(ResTy, LengthI, ArrayType::Normal,
/*IndexTypeQuals*/ 0);
   SL = StringLiteral::Create(Context, Str, StringLiteral::Ascii,
Index: lib/AST/Expr.cpp
===
--- lib/AST/Expr.cpp
+++ lib/AST/Expr.cpp
@@ -858,6 +858,17 @@
   assert(C.getAsConstantArrayType(Ty) &&
  "StringLiteral must be of constant array type!");
 
+  // OpenCL v1.1 s6.5.3: a string literal is in the constant address space.
+  assert((!C.getLangOpts().OpenCL ||
+  (C.getLangOpts().OpenCL &&
+   (Ty.getAddressSpace() == LangAS::Default ||
+Ty.getAddressSpace() == LangAS::opencl_constant))) &&
+ "StringLiteral must either have no address space or constant address "
+ "space!");
+
+  if (C.getLangOpts().OpenCL && Ty.getAddressSpace() == LangAS::Default)
+Ty = C.getAddrSpaceQualType(Ty, LangAS::opencl_constant);
+
   // Allocate enough space for the StringLiteral plus an array of locations for
   // any concatenated string tokens.
   void *Mem =
@@ -881,7 +892,10 @@
   void *Mem =
   C.Allocate(sizeof(StringLiteral) + sizeof(SourceLocation) * (NumStrs - 
1),
  alignof(StringLiteral));
-  StringLiteral *SL = new (Mem) StringLiteral(QualType());
+  StringLiteral *SL = new (Mem) StringLiteral(
+  C.getLangOpts().OpenCL
+  ? C.getAddrSpaceQualType(QualType(), LangAS::opencl_constant)
+  : QualType());
   SL->CharByteWidth = 0;
   SL->Length = 0;
   SL->NumConcatenated = NumStrs;


Index: test/SemaOpenCL/predefined-expr.cl
===
--- /dev/null
+++ test/SemaOpenCL/predefined-expr.cl
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 %s -verify
+
+void f() {
+  char *f1 = __func__;  //expected-error{{initializing 'char *' with an expression of type 'const __constant char *' changes address space of pointer}}
+  constant char *f2 = __func__; //expected-warning{{initializing '__constant char *' with an expression of type 'const __constant char [2]' discards qualifiers}}
+  constant const char *f3 = __func__;
+}
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -3052,6 +3052,8 @@
  /*Pascal*/ false, ResTy, Loc);
 } else {
   ResTy = Context.CharTy.withConst();
+  if (LangOpts.OpenCL)
+ResTy = Context.getAddrSpaceQualType(ResTy, LangAS::opencl_constant);
   ResTy = Context.getConstantArrayType(ResTy, LengthI, ArrayType::Normal,
/*IndexTypeQuals*/ 0);
   SL = StringLiteral::Create(Context, Str, StringLiteral::Ascii,
Index: lib/AST/Expr.cpp
===
--- lib/AST/Expr.cpp
+++ lib/AST/Expr.cpp
@@ -858,6 +858,17 @@
   assert(C.getAsConstantArrayType(Ty) &&
  "StringLiteral must be of constant array type!");
 
+  // OpenCL v1.1 s6.5.3: a string literal is in the constant address space.
+  assert((!C.getLangOpts().OpenCL ||
+  (C.getLangOpts().OpenCL &&
+   (Ty.getAddressSpace() == LangAS::Default ||
+Ty.getAddressSpace() == LangAS::opencl_constant))) &&
+ "StringLiteral must either have no address space or constant address "
+ "space!");
+
+  if (C.getLangOpts().OpenCL && Ty.getAddressSpace() == LangAS::Default)
+Ty = C.getAddrSpaceQualType(Ty, LangAS::opencl_constant);
+
   // Allocate enough space for the StringLiteral plus an array of locations for
   // any concatenated string tokens.
   void *Mem =
@@ -

[PATCH] D46131: Add Microsoft Mangling for OpenCL Half Type

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

lgtm


Repository:
  rC Clang

https://reviews.llvm.org/D46131



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


[PATCH] D46049: [OpenCL] Add constant address space to __func__ in AST

2018-04-26 Thread Alexey Bader via Phabricator via cfe-commits
bader accepted this revision.
bader added inline comments.
This revision is now accepted and ready to land.



Comment at: lib/Sema/SemaExpr.cpp:3056
+  if (LangOpts.OpenCL)
+ResTy = Context.getAddrSpaceQualType(ResTy, LangAS::opencl_constant);
   ResTy = Context.getConstantArrayType(ResTy, LengthI, ArrayType::Normal,

Do we still need this?



https://reviews.llvm.org/D46049



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


[PATCH] D46135: [Driver, CodeGen] add options to enable/disable an FP cast optimization

2018-04-26 Thread Sanjay Patel via Phabricator via cfe-commits
spatel created this revision.
spatel added reviewers: jgorbe, chandlerc, scanon, hans, echristo.
Herald added a subscriber: mcrosier.

As discussed in the post-commit thread for:
https://reviews.llvm.org/rL330437 ( 
http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20180423/545906.html )

We need a way to opt-out of a float-to-int-to-float cast optimization because 
too much existing code relies on the platform-specific undefined result of 
those casts when the float-to-int overflows.

I speculatively committed the LLVM changes associated with adding this function 
attribute, but I'll change the name/implementation if there's a better 
alternative:
https://reviews.llvm.org/rL330947
https://reviews.llvm.org/rL330950
https://reviews.llvm.org/rL330951

Also as suggested, I changed the LLVM doc to mention the specific sanitizer 
flag that catches this problem:
https://reviews.llvm.org/rL330958

I tested the end-to-end results on x86 and see the expected outcome: 'roundss' 
is no longer produced in place of cvttss2si + cvtsi2ss with default 
optimization.


https://reviews.llvm.org/D46135

Files:
  docs/UsersManual.rst
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/CGCall.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/no-junk-ftrunc.c
  test/Driver/fast-math.c

Index: test/Driver/fast-math.c
===
--- test/Driver/fast-math.c
+++ test/Driver/fast-math.c
@@ -287,3 +287,27 @@
 // RUN: %clang -### -ftrapping-math -fno-trapping-math -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NO-TRAPPING-MATH %s
 // CHECK-NO-TRAPPING-MATH: "-fno-trapping-math"
+
+// This isn't fast-math, but the option is handled in the same place as other FP params.
+// Last option wins, and the flag is passed by default (FIXME). 
+
+// RUN: %clang -### -ffp-cast-overflow-workaround -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-FPOV-WORKAROUND %s
+// CHECK-FPOV-WORKAROUND: "-cc1"
+// CHECK-FPOV-WORKAROUND: "-ffp-cast-overflow-workaround"
+
+// RUN: %clang -### -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-FPOV-WORKAROUND-DEFAULT %s
+// CHECK-FPOV-WORKAROUND-DEFAULT: "-cc1"
+// CHECK-FPOV-WORKAROUND-DEFAULT: "-ffp-cast-overflow-workaround"
+
+// RUN: %clang -### -fno-fp-cast-overflow-workaround -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NO-FPOV-WORKAROUND %s
+// CHECK-NO-FPOV-WORKAROUND: "-cc1"
+// CHECK-NO-FPOV-WORKAROUND-NOT: "-ffp-cast-overflow-workaround"
+
+// RUN: %clang -### -ffp-cast-overflow-workaround -fno-fp-cast-overflow-workaround -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NO-FPOV-WORKAROUND-OVERRIDE %s
+// CHECK-NO-FPOV-WORKAROUND-OVERRIDE: "-cc1"
+// CHECK-NO-FPOV-WORKAROUND-OVERRIDE-NOT: "-ffp-cast-overflow-workaround"
+
Index: test/CodeGen/no-junk-ftrunc.c
===
--- test/CodeGen/no-junk-ftrunc.c
+++ test/CodeGen/no-junk-ftrunc.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -S -ffp-cast-overflow-workaround %s -emit-llvm -o - | FileCheck %s
+
+// CHECK-LABEL: main
+// CHECK: attributes #0 = {{.*}}"fp-cast-overflow-workaround"="true"{{.*}}
+
+int main() {
+  return 0;
+}
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -699,6 +699,8 @@
   Opts.Reciprocals = Args.getAllArgValues(OPT_mrecip_EQ);
   Opts.ReciprocalMath = Args.hasArg(OPT_freciprocal_math);
   Opts.NoTrappingMath = Args.hasArg(OPT_fno_trapping_math);
+  Opts.FPCastOverflowWorkaround = Args.hasArg(OPT_ffp_cast_overflow_workaround);
+
   Opts.NoZeroInitializedInBSS = Args.hasArg(OPT_mno_zero_initialized_in_bss);
   Opts.NumRegisterParameters = getLastArgIntValue(Args, OPT_mregparm, 0, Diags);
   Opts.NoExecStack = Args.hasArg(OPT_mno_exec_stack);
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -2241,6 +2241,14 @@
 CmdArgs.push_back("-mfpmath");
 CmdArgs.push_back(A->getValue());
   }
+
+  // Disable a codegen optimization for floating-point casts. This is only
+  // intended to be temporarily defaulted to 'true' to give users time to fix
+  // their code.
+  if (Args.hasFlag(options::OPT_ffp_cast_overflow_workaround,
+   options::OPT_fno_fp_cast_overflow_workaround,
+   true))
+CmdArgs.push_back("-ffp-cast-overflow-workaround");
 }
 
 static void RenderAnalyzerOptions(const ArgList &Args, ArgStringList &CmdArgs,
Index: lib/CodeGen/CGCall.cpp
===
--- lib/CodeGen/CGCall.cpp
+++ lib/CodeGen/CGCall.cpp
@@ -1727,6 +1727,9 @@
 FuncAttrs.addAttribute("no-trapping-math",
llvm::toStringRef(CodeGenOpts.NoT

[PATCH] D45917: Pass -Oz/-Os along to the backend

2018-04-26 Thread Jessica Paquette via Phabricator via cfe-commits
paquette abandoned this revision.
paquette added a comment.

We decided it'd be better to just use function attributes for the outliner, so 
I'm abandoning this.


https://reviews.llvm.org/D45917



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


[PATCH] D46022: [OpenCL] Restrict various keywords in OpenCL C++ mode

2018-04-26 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/Parse/ParseStmtAsm.cpp:696
+return StmtError();
+  }
+

svenvh wrote:
> rjmccall wrote:
> > svenvh wrote:
> > > rjmccall wrote:
> > > > You might consider parsing the statement normally and then just 
> > > > diagnosing after the fact, maybe in Sema.  You'd have to add the check 
> > > > in a couple different places, though.
> > > Precisely the reason why I did it in the parser, otherwise we'd have to 
> > > duplicate the check in multiple places.
> > The downside of this is that the parser recovery is probably very bad.  But 
> > since this is asm, it's not likely to matter too much.
> > 
> > ...is this *also* really only an OpenCL C++ restriction?  Maybe we should 
> > read this one as a general restriction that happens to have been overlooked 
> > in the OpenCL C spec.
> Yes, `asm` is only explicitly restricted in OpenCL C++.  Not sure if it's 
> safe to assume `asm` has been overlooked for OpenCL C though, it's not 
> explicitly forbidden so people may be using it.
Do you have any contact with the OpenCL committee?  You might want to collect 
these issues and present them to them.  They may just not be aware that `asm` 
is just as much a feature in C as it is in C++, and it would be good to 
understand what the purpose of the `goto` restriction is.



Comment at: lib/Sema/DeclSpec.cpp:621
+// OpenCL C++ 1.0 s2.9: the thread_local storage qualifier is not
+// supported.
+case TSCS_thread_local:

svenvh wrote:
> rjmccall wrote:
> > svenvh wrote:
> > > rjmccall wrote:
> > > > svenvh wrote:
> > > > > rjmccall wrote:
> > > > > > Do you really care about the spelling of the specifier?  Presumably 
> > > > > > `__thread` (the GNU extension) and `_Thread_local` (the C11 
> > > > > > feature) are unsupported; where are those diagnosed?
> > > > > Fair enough, I have updated the patch to just reject any thread 
> > > > > qualifier here.
> > > > I meant it as a question, but I take it from this response that we 
> > > > don't actually diagnose these.
> > > > 
> > > > It might make more sense to diagnose this in 
> > > > `Sema::ActOnVariableDeclarator`, where we're already doing some 
> > > > checking about whether e.g. the target supports the feature.
> > > We do actually diagnose the others in `Sema::ActOnVariableDeclarator` 
> > > ("thread-local storage is not supported for the current target").  But 
> > > your question made me realize there is no real need to differentiate here 
> > > for the OpenCL C++ case.
> > Okay.  So we can remove this code, then.
> Sorry if my previous comment was ambiguous: I meant here we now reject *any* 
> thread storage class specifier for OpenCL C++, not just the `thread_local` 
> spelling (my original patch was only rejecting `TSCS_thread_local`).
But you said we already diagnose this in Sema, so we don't need any code here.  
If you want a special-case diagnostic, that's easy to do there; CUDA already 
does the same thing.


https://reviews.llvm.org/D46022



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


[PATCH] D46135: [Driver, CodeGen] add options to enable/disable an FP cast optimization

2018-04-26 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added inline comments.



Comment at: test/CodeGen/no-junk-ftrunc.c:1
+// RUN: %clang_cc1 -S -ffp-cast-overflow-workaround %s -emit-llvm -o - | 
FileCheck %s
+

For a good measure, i'd add one more `RUN` line to test that it is currently 
the default.
(Yes, i noticed that it is already tested in `test/Driver/fast-math.c`)


https://reviews.llvm.org/D46135



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


[PATCH] D45884: [Sema] Fix parsing of anonymous union in language linkage specification

2018-04-26 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai accepted this revision.
vsapsai added inline comments.
This revision is now accepted and ready to land.



Comment at: Sema/SemaDecl.cpp:4651-4653
+
+  DeclContext *OwnerScope = Owner->getRedeclContext();
+

I think the code style favours avoiding excessive vertical whitespace and I 
don't feel like this statement is semantically far enough from the surrounding 
code to be separated from it. I haven't found a specific [LLVM Coding 
Standards](https://llvm.org/docs/CodingStandards.html) rule, so in this case it 
is my personal opinion and actual formatting decision is up to you.

Other than that I have no other comments.


https://reviews.llvm.org/D45884



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


[PATCH] D46139: Add template type and value parameter metadata nodes to template variable specializations.

2018-04-26 Thread Matthew Voss via Phabricator via cfe-commits
ormris created this revision.
ormris added reviewers: dblaikie, probinson, aprantl, JDevlieghere, clayborg.

Depends on LLVM patch: https://reviews.llvm.org/D46138

Resolves PR22119


Repository:
  rC Clang

https://reviews.llvm.org/D46139

Files:
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CGDebugInfo.h
  test/CodeGenCXX/debug-info-template-member.cpp

Index: test/CodeGenCXX/debug-info-template-member.cpp
===
--- test/CodeGenCXX/debug-info-template-member.cpp
+++ test/CodeGenCXX/debug-info-template-member.cpp
@@ -22,6 +22,19 @@
 // CHECK: [[X]] = !DIGlobalVariableExpression(var: [[XV:.*]], expr: !DIExpression())
 // CHECK: [[XV]] = distinct !DIGlobalVariable(name: "x",
 // CHECK-SAME:type: ![[OUTER_FOO_INNER_ID:[0-9]+]]
+//
+// CHECK: {{![0-9]+}} = distinct !DIGlobalVariable(
+// CHECK-SAME: name: "var"
+// CHECK-SAME: templateParams: {{![0-9]+}}
+// CHECK: !DITemplateTypeParameter(name: "T", type: [[TY:![0-9]+]])
+// CHECK: {{![0-9]+}} = distinct !DIGlobalVariable(
+// CHECK-SAME: name: "var"
+// CHECK-SAME: templateParams: {{![0-9]+}}
+// CHECK: !DITemplateTypeParameter(name: "P", type: {{![0-9]+}})
+// CHECK: {{![0-9]+}} = distinct !DIGlobalVariable(
+// CHECK-SAME: name: "varray"
+// CHECK-SAME: templateParams: {{![0-9]+}}
+// CHECK: !DITemplateValueParameter(name: "N", type: [[TY]], value: i32 1)
 
 // CHECK: ![[OUTER_FOO_INNER_ID:[0-9]*]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "inner"{{.*}}, identifier:
 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "foo"
@@ -103,3 +116,15 @@
 // declaration/reference in the compile unit.
 // CHECK: !DISubprogram(name: "MyClass"
 // CHECK-SAME:  scope: [[C]]
+
+template 
+T var = T();
+template 
+P var = P();
+template 
+T varray[N];
+void f3() {
+  var = 1;
+  var = 1;
+  varray[0] = 1;
+}
Index: lib/CodeGen/CGDebugInfo.h
===
--- lib/CodeGen/CGDebugInfo.h
+++ lib/CodeGen/CGDebugInfo.h
@@ -244,6 +244,11 @@
   llvm::DINodeArray CollectFunctionTemplateParams(const FunctionDecl *FD,
   llvm::DIFile *Unit);
 
+  /// A helper function to collect debug info for function template
+  /// parameters.
+  llvm::DINodeArray CollectVarTemplateParams(const VarDecl *VD,
+ llvm::DIFile *Unit);
+
   /// A helper function to collect debug info for template
   /// parameters.
   llvm::DINodeArray
@@ -621,7 +626,9 @@
   /// Collect various properties of a VarDecl.
   void collectVarDeclProps(const VarDecl *VD, llvm::DIFile *&Unit,
unsigned &LineNo, QualType &T, StringRef &Name,
-   StringRef &LinkageName, llvm::DIScope *&VDContext);
+   StringRef &LinkageName,
+   llvm::MDTuple *&templateParameters,
+   llvm::DIScope *&VDContext);
 
   /// Allocate a copy of \p A using the DebugInfoNames allocator
   /// and return a reference to it. If multiple arguments are given the strings
Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -41,6 +41,7 @@
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/IR/Instructions.h"
 #include "llvm/IR/Intrinsics.h"
+#include "llvm/IR/Metadata.h"
 #include "llvm/IR/Module.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MD5.h"
@@ -1679,6 +1680,30 @@
   return llvm::DINodeArray();
 }
 
+llvm::DINodeArray CGDebugInfo::CollectVarTemplateParams(const VarDecl *VL,
+llvm::DIFile *Unit) {
+  if (auto *TS = dyn_cast(VL)) {
+if (TS->getSpecializedTemplateOrPartial()
+.is()) {
+  const TemplateParameterList *TList =
+  TS->getSpecializedTemplateOrPartial()
+  .get()
+  ->getTemplateParameters();
+  return CollectTemplateParams(TList, TS->getTemplateArgs().asArray(),
+   Unit);
+}
+
+if (TS->getSpecializedTemplateOrPartial().is()) {
+  const TemplateParameterList *TList = TS->getSpecializedTemplateOrPartial()
+   .get()
+   ->getTemplateParameters();
+  return CollectTemplateParams(TList, TS->getTemplateArgs().asArray(),
+   Unit);
+}
+  }
+  return llvm::DINodeArray();
+}
+
 llvm::DINodeArray CGDebugInfo::CollectCXXTemplateParams(
 const ClassTemplateSpecializationDecl *TSpecial, llvm::DIFile *Unit) {
   // Always get the full list of parameters, not just the ones from
@@ -2965,6 +2990,7 @@
 void CGDebugInfo::collectVarDeclProps(const VarDecl *VD, llvm::DIFile *&Unit,
   unsigned &LineNo, QualType &T,
   

[PATCH] D46049: [OpenCL] Add constant address space to __func__ in AST

2018-04-26 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: lib/Sema/SemaExpr.cpp:3059
/*IndexTypeQuals*/ 0);
   SL = StringLiteral::Create(Context, Str, StringLiteral::Ascii,
  /*Pascal*/ false, ResTy, Loc);

bader wrote:
> Will it work if we fix this issue inside StringLiteral::Create method?
> I just hope it will help us avoid code duplication.
I have added the address space to the creation of `StringLiteral`, but 
unfortunately it doesn't seems like we can remove similar code in other places 
because `QualType` created for `StringLiteral` is also used elsewhere and has 
to match (contain right address space). I.e. here is it used further down to 
create `PredefinedExpr`. 

So not sure there is any value in doing the change in `StringLiteral` 
construction really. Unless we could keep it and use `getType()` from 
`StringLiteral` to resent the `QualType` to be used further down. Let me know 
what you think about it?


https://reviews.llvm.org/D46049



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


[PATCH] D46135: [Driver, CodeGen] add options to enable/disable an FP cast optimization

2018-04-26 Thread Sanjay Patel via Phabricator via cfe-commits
spatel added inline comments.



Comment at: test/CodeGen/no-junk-ftrunc.c:1
+// RUN: %clang_cc1 -S -ffp-cast-overflow-workaround %s -emit-llvm -o - | 
FileCheck %s
+

lebedev.ri wrote:
> For a good measure, i'd add one more `RUN` line to test that it is currently 
> the default.
> (Yes, i noticed that it is already tested in `test/Driver/fast-math.c`)
The driver alone is handling the default setting, so it passes this flag to the 
front-end only when we're going to disable the transform. Ie, the driver eats 
"-fno-fp-cast-overflow-workaround" and sends nothing in that case to the 
front-end. 

So there's not currently any case where the function attribute will be 
"fp-cast-overflow-workaround=false", but I left that as a possibility in case 
we decide to lift the limit at a finer granularity (scalar vs. vector etc).

I may be misunderstanding the question/suggestion - do we want the front-end to 
independently have a default setting?


https://reviews.llvm.org/D46135



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


[PATCH] D46139: Add template type and value parameter metadata nodes to template variable specializations.

2018-04-26 Thread Paul Robinson via Phabricator via cfe-commits
probinson added inline comments.



Comment at: lib/CodeGen/CGDebugInfo.cpp:3023
+  templateParameters = parameterNodes.get();
+
   // Since we emit declarations (DW_AT_members) for static members, place the

Naively it looks like it should be possible to put the local into a scope under 
the if:
```
if (isa<...>(VD)) {
  llvm::DINodeArray parameterNodes = CollectVarTemplateParams(VD, &*Unit);
  templateParameters = parameterNodes.get();
}
```
but you told me this caused crashes.  I don't understand that, as 
templateParameters is itself a formal parameter, so you're really returning the 
node array to the caller?
(My understanding is at least partly hampered by being unable to find the 
definition of `DINodeArray`, if somebody can point it out that would be 
helpful.)


Repository:
  rC Clang

https://reviews.llvm.org/D46139



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


[PATCH] D46139: Add template type and value parameter metadata nodes to template variable specializations.

2018-04-26 Thread Matthew Voss via Phabricator via cfe-commits
ormris added a comment.

Thanks for spotting that @probinson. Will update.


Repository:
  rC Clang

https://reviews.llvm.org/D46139



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


[PATCH] D46112: Allow _Atomic to be specified on incomplete types

2018-04-26 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

This generally makes sense.

Need some tests to make sure we emit an appropriate error if you try to 
actually use atomic operators (load/store) or intrinsics (__atomic_is_lock_free 
etc.) with an incomplete type.  And a test that code generation emits something 
appropriate.




Comment at: lib/Sema/SemaType.cpp:8022
+else if (LangOpts.CPlusPlus && isCompleteType(Loc, T) &&
+ !T.isTriviallyCopyableType(Context))
   // Some other non-trivially-copyable type (probably a C++ class)

If you're going to allow incomplete types in C++, you'll need some code to 
handle the case where the type is initially incomplete, but completed later.


https://reviews.llvm.org/D46112



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


[PATCH] D46132: [X86] Make __builtin_ia32_readeflags_u32 and __builtin_ia32_writeeflags_u32 only available on 32-bit targets.

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

Looks good.


Repository:
  rC Clang

https://reviews.llvm.org/D46132



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


[PATCH] D46135: [Driver, CodeGen] add options to enable/disable an FP cast optimization

2018-04-26 Thread Jorge Gorbe via Phabricator via cfe-commits
jgorbe added a comment.

Can't comment much on the patch itself (I'm still not very familiar with the 
codebase, I'll leave that to the other reviewers), but thanks a lot for 
responding so quickly! :)


https://reviews.llvm.org/D46135



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


[PATCH] D46143: [clang-format/ObjC] Use getIdentifierInfo() instead of tok::identifier

2018-04-26 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton created this revision.
benhamilton added reviewers: djasper, jolesiak.
Herald added subscribers: cfe-commits, klimek.

Previously, we checked tokens for `tok::identifier` to see if they
were identifiers inside an Objective-C selector.

However, this missed C++ keywords like `new` and `delete`.

To fix this, this diff uses `getIdentifierInfo()` to find
identifiers or keywords inside Objective-C selectors.

Test Plan: New tests added. Ran tests with:

  % make -j16 FormatTests && ./tools/clang/unittests/Format/FormatTests


Repository:
  rC Clang

https://reviews.llvm.org/D46143

Files:
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTestObjC.cpp


Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -945,15 +945,26 @@
" }]) {\n}");
 }
 
-TEST_F(FormatTestObjC, ObjCNew) {
+TEST_F(FormatTestObjC, ObjCCxxKeywords) {
   verifyFormat("+ (instancetype)new {\n"
"  return nil;\n"
"}\n");
   verifyFormat("+ (instancetype)myNew {\n"
"  return [self new];\n"
"}\n");
   verifyFormat("SEL NewSelector(void) { return @selector(new); }\n");
   verifyFormat("SEL MacroSelector(void) { return MACRO(new); }\n");
+  verifyFormat("+ (instancetype)delete {\n"
+   "  return nil;\n"
+   "}\n");
+  verifyFormat("+ (instancetype)myDelete {\n"
+   "  return [self delete];\n"
+   "}\n");
+  verifyFormat("SEL DeleteSelector(void) { return @selector(delete); }\n");
+  verifyFormat("SEL MacroSelector(void) { return MACRO(delete); }\n");
+  verifyFormat("MACRO(new:)\n");
+  verifyFormat("MACRO(delete:)\n");
+  verifyFormat("foo = @{MACRO(new:) : MACRO(delete:)}\n");
 }
 
 TEST_F(FormatTestObjC, ObjCLiterals) {
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -703,9 +703,10 @@
   Tok->Type = TT_CtorInitializerColon;
 else
   Tok->Type = TT_InheritanceColon;
-  } else if (Tok->Previous->is(tok::identifier) && Tok->Next &&
+  } else if (Tok->Previous->Tok.getIdentifierInfo() && Tok->Next &&
  (Tok->Next->isOneOf(tok::r_paren, tok::comma) ||
-  Tok->Next->startsSequence(tok::identifier, tok::colon))) {
+  (Tok->Next->Tok.getIdentifierInfo() && Tok->Next->Next &&
+   Tok->Next->Next->is(tok::colon {
 // This handles a special macro in ObjC code where selectors including
 // the colon are passed as macro arguments.
 Tok->Type = TT_ObjCMethodExpr;
@@ -1346,7 +1347,7 @@
  TT_LeadingJavaAnnotation)) {
 Current.Type = Current.Previous->Type;
   }
-} else if (Current.isOneOf(tok::identifier, tok::kw_new) &&
+} else if (Current.Tok.getIdentifierInfo() &&
// FIXME(bug 36976): ObjC return types shouldn't use 
TT_CastRParen.
Current.Previous && Current.Previous->is(TT_CastRParen) &&
Current.Previous->MatchingParen &&
@@ -2650,7 +2651,7 @@
   if (Line.Type == LT_ObjCMethodDecl) {
 if (Left.is(TT_ObjCMethodSpecifier))
   return true;
-if (Left.is(tok::r_paren) && Right.isOneOf(tok::identifier, tok::kw_new))
+if (Left.is(tok::r_paren) && Right.Tok.getIdentifierInfo())
   // Don't space between ')' and  or ')' and 'new'. 'new' is not a
   // keyword in Objective-C, and '+ (instancetype)new;' is a standard class
   // method declaration.
@@ -3128,6 +3129,7 @@
 for (unsigned i = 0, e = Tok->FakeLParens.size(); i != e; ++i)
   llvm::errs() << Tok->FakeLParens[i] << "/";
 llvm::errs() << " FakeRParens=" << Tok->FakeRParens;
+llvm::errs() << " II=" << Tok->Tok.getIdentifierInfo();
 llvm::errs() << " Text='" << Tok->TokenText << "'\n";
 if (!Tok->Next)
   assert(Tok == Line.Last);


Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -945,15 +945,26 @@
" }]) {\n}");
 }
 
-TEST_F(FormatTestObjC, ObjCNew) {
+TEST_F(FormatTestObjC, ObjCCxxKeywords) {
   verifyFormat("+ (instancetype)new {\n"
"  return nil;\n"
"}\n");
   verifyFormat("+ (instancetype)myNew {\n"
"  return [self new];\n"
"}\n");
   verifyFormat("SEL NewSelector(void) { return @selector(new); }\n");
   verifyFormat("SEL MacroSelector(void) { return MACRO(new); }\n");
+  verifyFormat("+ (instancetype)delete {\n"
+   "  return nil;\n"
+   "}\n");
+  verifyFormat("+ (instancetype)myDelete {\n"
+   "  return [self delete];\n"
+   "}\n");
+  ver

r330987 - [X86] Make __builtin_ia32_readeflags_u32 and __builtin_ia32_writeeflags_u32 only available on 32-bit targets.

2018-04-26 Thread Craig Topper via cfe-commits
Author: ctopper
Date: Thu Apr 26 13:14:46 2018
New Revision: 330987

URL: http://llvm.org/viewvc/llvm-project?rev=330987&view=rev
Log:
[X86] Make __builtin_ia32_readeflags_u32 and __builtin_ia32_writeeflags_u32 
only available on 32-bit targets.

These builtins can't be handled by the backend on 64-bit targets. So error up 
front instead of throwing an isel error.

Fixes PR37225

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

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/Sema/builtins-x86.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=330987&r1=330986&r2=330987&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Apr 26 13:14:46 
2018
@@ -8251,6 +8251,8 @@ def err_systemz_invalid_tabort_code : Er
   "invalid transaction abort code">;
 def err_64_bit_builtin_32_bit_tgt : Error<
   "this builtin is only available on 64-bit targets">;
+def err_32_bit_builtin_64_bit_tgt : Error<
+  "this builtin is only available on 32-bit targets">;
 def err_builtin_x64_aarch64_only : Error<
   "this builtin is only available on x86-64 and aarch64 targets">;
 def err_ppc_builtin_only_on_pwr7 : Error<

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=330987&r1=330986&r2=330987&view=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Thu Apr 26 13:14:46 2018
@@ -2309,6 +2309,17 @@ bool Sema::CheckX86BuiltinGatherScatterS
 << Arg->getSourceRange();
 }
 
+static bool isX86_32Builtin(unsigned BuiltinID) {
+  // These builtins only work on x86-32 targets.
+  switch (BuiltinID) {
+  case X86::BI__builtin_ia32_readeflags_u32:
+  case X86::BI__builtin_ia32_writeeflags_u32:
+return true;
+  }
+
+  return false;
+}
+
 bool Sema::CheckX86BuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
   if (BuiltinID == X86::BI__builtin_cpu_supports)
 return SemaBuiltinCpuSupports(*this, TheCall);
@@ -2316,6 +2327,12 @@ bool Sema::CheckX86BuiltinFunctionCall(u
   if (BuiltinID == X86::BI__builtin_cpu_is)
 return SemaBuiltinCpuIs(*this, TheCall);
 
+  // Check for 32-bit only builtins on a 64-bit target.
+  const llvm::Triple &TT = Context.getTargetInfo().getTriple();
+  if (TT.getArch() != llvm::Triple::x86 && isX86_32Builtin(BuiltinID))
+return Diag(TheCall->getCallee()->getLocStart(),
+diag::err_32_bit_builtin_64_bit_tgt);
+
   // If the intrinsic has rounding or SAE make sure its valid.
   if (CheckX86BuiltinRoundingOrSAE(BuiltinID, TheCall))
 return true;

Modified: cfe/trunk/test/Sema/builtins-x86.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/builtins-x86.c?rev=330987&r1=330986&r2=330987&view=diff
==
--- cfe/trunk/test/Sema/builtins-x86.c (original)
+++ cfe/trunk/test/Sema/builtins-x86.c Thu Apr 26 13:14:46 2018
@@ -16,6 +16,11 @@ typedef unsigned char __mmask8;
 typedef unsigned short __mmask16;
 typedef unsigned int __mmask32;
 
+void call_x86_32_builtins(void) {
+  (void)__builtin_ia32_readeflags_u32(); // 
expected-error{{this builtin is only available on 32-bit targets}}
+  (void)__builtin_ia32_writeeflags_u32(4);   // 
expected-error{{this builtin is only available on 32-bit targets}}
+}
+
 __m128 test__builtin_ia32_cmpps(__m128 __a, __m128 __b) {
   __builtin_ia32_cmpps(__a, __b, 32); // expected-error {{argument should be a 
value from 0 to 31}}
 }


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


[PATCH] D46132: [X86] Make __builtin_ia32_readeflags_u32 and __builtin_ia32_writeeflags_u32 only available on 32-bit targets.

2018-04-26 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL330987: [X86] Make __builtin_ia32_readeflags_u32 and 
__builtin_ia32_writeeflags_u32… (authored by ctopper, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D46132

Files:
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/lib/Sema/SemaChecking.cpp
  cfe/trunk/test/Sema/builtins-x86.c


Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8251,6 +8251,8 @@
   "invalid transaction abort code">;
 def err_64_bit_builtin_32_bit_tgt : Error<
   "this builtin is only available on 64-bit targets">;
+def err_32_bit_builtin_64_bit_tgt : Error<
+  "this builtin is only available on 32-bit targets">;
 def err_builtin_x64_aarch64_only : Error<
   "this builtin is only available on x86-64 and aarch64 targets">;
 def err_ppc_builtin_only_on_pwr7 : Error<
Index: cfe/trunk/test/Sema/builtins-x86.c
===
--- cfe/trunk/test/Sema/builtins-x86.c
+++ cfe/trunk/test/Sema/builtins-x86.c
@@ -16,6 +16,11 @@
 typedef unsigned short __mmask16;
 typedef unsigned int __mmask32;
 
+void call_x86_32_builtins(void) {
+  (void)__builtin_ia32_readeflags_u32(); // 
expected-error{{this builtin is only available on 32-bit targets}}
+  (void)__builtin_ia32_writeeflags_u32(4);   // 
expected-error{{this builtin is only available on 32-bit targets}}
+}
+
 __m128 test__builtin_ia32_cmpps(__m128 __a, __m128 __b) {
   __builtin_ia32_cmpps(__a, __b, 32); // expected-error {{argument should be a 
value from 0 to 31}}
 }
Index: cfe/trunk/lib/Sema/SemaChecking.cpp
===
--- cfe/trunk/lib/Sema/SemaChecking.cpp
+++ cfe/trunk/lib/Sema/SemaChecking.cpp
@@ -2309,13 +2309,30 @@
 << Arg->getSourceRange();
 }
 
+static bool isX86_32Builtin(unsigned BuiltinID) {
+  // These builtins only work on x86-32 targets.
+  switch (BuiltinID) {
+  case X86::BI__builtin_ia32_readeflags_u32:
+  case X86::BI__builtin_ia32_writeeflags_u32:
+return true;
+  }
+
+  return false;
+}
+
 bool Sema::CheckX86BuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
   if (BuiltinID == X86::BI__builtin_cpu_supports)
 return SemaBuiltinCpuSupports(*this, TheCall);
 
   if (BuiltinID == X86::BI__builtin_cpu_is)
 return SemaBuiltinCpuIs(*this, TheCall);
 
+  // Check for 32-bit only builtins on a 64-bit target.
+  const llvm::Triple &TT = Context.getTargetInfo().getTriple();
+  if (TT.getArch() != llvm::Triple::x86 && isX86_32Builtin(BuiltinID))
+return Diag(TheCall->getCallee()->getLocStart(),
+diag::err_32_bit_builtin_64_bit_tgt);
+
   // If the intrinsic has rounding or SAE make sure its valid.
   if (CheckX86BuiltinRoundingOrSAE(BuiltinID, TheCall))
 return true;


Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8251,6 +8251,8 @@
   "invalid transaction abort code">;
 def err_64_bit_builtin_32_bit_tgt : Error<
   "this builtin is only available on 64-bit targets">;
+def err_32_bit_builtin_64_bit_tgt : Error<
+  "this builtin is only available on 32-bit targets">;
 def err_builtin_x64_aarch64_only : Error<
   "this builtin is only available on x86-64 and aarch64 targets">;
 def err_ppc_builtin_only_on_pwr7 : Error<
Index: cfe/trunk/test/Sema/builtins-x86.c
===
--- cfe/trunk/test/Sema/builtins-x86.c
+++ cfe/trunk/test/Sema/builtins-x86.c
@@ -16,6 +16,11 @@
 typedef unsigned short __mmask16;
 typedef unsigned int __mmask32;
 
+void call_x86_32_builtins(void) {
+  (void)__builtin_ia32_readeflags_u32(); // expected-error{{this builtin is only available on 32-bit targets}}
+  (void)__builtin_ia32_writeeflags_u32(4);   // expected-error{{this builtin is only available on 32-bit targets}}
+}
+
 __m128 test__builtin_ia32_cmpps(__m128 __a, __m128 __b) {
   __builtin_ia32_cmpps(__a, __b, 32); // expected-error {{argument should be a value from 0 to 31}}
 }
Index: cfe/trunk/lib/Sema/SemaChecking.cpp
===
--- cfe/trunk/lib/Sema/SemaChecking.cpp
+++ cfe/trunk/lib/Sema/SemaChecking.cpp
@@ -2309,13 +2309,30 @@
 << Arg->getSourceRange();
 }
 
+static bool isX86_32Builtin(unsigned BuiltinID) {
+  // These builtins only work on x86-32 targets.
+  switch (BuiltinID) {
+  case X86::BI__builtin_ia32_readeflags_u32:
+  case X86::BI__builtin_ia32_writeeflags_u32:

[PATCH] D46139: Add template type and value parameter metadata nodes to template variable specializations.

2018-04-26 Thread Matthew Voss via Phabricator via cfe-commits
ormris abandoned this revision.
ormris added a comment.

After some further inspection, support for the LLVM side of patch needs a few 
significant additions. Abandoning this revision.


Repository:
  rC Clang

https://reviews.llvm.org/D46139



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


[PATCH] D46135: [Driver, CodeGen] add options to enable/disable an FP cast optimization

2018-04-26 Thread Chandler Carruth via Phabricator via cfe-commits
chandlerc added inline comments.



Comment at: docs/UsersManual.rst:1260-1265
+   Enable or disable a code generation optimization that may convert a
+   cast of a floating-point value to integer and back to floating-point
+   into the equivalent of the math libary's 'trunc()' function. This
+   optimization is disabled by default to avoid problems associated
+   with relying on the undefined behavior of an overflowing cast, but 
+   that limitation should be considered temporary. 

I would phrase this the other way around (and I think the flag name is already 
phrased the other way around?):

"""
Enable a workaround for incorrect code that casts floating point values to 
integers where the floating point value is not representable in the integer 
type. This code is incorrect according to the language standard, but this flag 
will attempt to generate code to cause .
"""

Essentially, this should be more like '-fwrapv'. Also, I think the default 
should be what the specification says. People can explicitly pass this flag if 
their code is broken in this way.


https://reviews.llvm.org/D46135



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


[PATCH] D46049: [OpenCL] Add constant address space to __func__ in AST

2018-04-26 Thread Alexey Bader via Phabricator via cfe-commits
bader added inline comments.



Comment at: lib/AST/Expr.cpp:870
+  if (C.getLangOpts().OpenCL && Ty.getAddressSpace() == LangAS::Default)
+Ty = C.getAddrSpaceQualType(Ty, LangAS::opencl_constant);
+

As `Ty` is passed by value, shouldn't we accept only data located in constant 
address space?



Comment at: lib/Sema/SemaExpr.cpp:3057
+ResTy = Context.getAddrSpaceQualType(ResTy, LangAS::opencl_constant);
   ResTy = Context.getConstantArrayType(ResTy, LengthI, ArrayType::Normal,
/*IndexTypeQuals*/ 0);

String type can only be a constant arrays.
Can we set constant address space inside this getter for OpenCL language?
Or we might want constant array in other address spaces e.g. private? 


https://reviews.llvm.org/D46049



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


[PATCH] D46135: [Driver, CodeGen] add options to enable/disable an FP cast optimization

2018-04-26 Thread Sanjay Patel via Phabricator via cfe-commits
spatel added inline comments.



Comment at: docs/UsersManual.rst:1260-1265
+   Enable or disable a code generation optimization that may convert a
+   cast of a floating-point value to integer and back to floating-point
+   into the equivalent of the math libary's 'trunc()' function. This
+   optimization is disabled by default to avoid problems associated
+   with relying on the undefined behavior of an overflowing cast, but 
+   that limitation should be considered temporary. 

chandlerc wrote:
> I would phrase this the other way around (and I think the flag name is 
> already phrased the other way around?):
> 
> """
> Enable a workaround for incorrect code that casts floating point values to 
> integers where the floating point value is not representable in the integer 
> type. This code is incorrect according to the language standard, but this 
> flag will attempt to generate code to cause  the flag enabled>.
> """
> 
> Essentially, this should be more like '-fwrapv'. Also, I think the default 
> should be what the specification says. People can explicitly pass this flag 
> if their code is broken in this way.
Ah - did I misinterpret the earlier comments? 

I thought we need to have the work-around 'on' by default as the immediate fix 
for broken programs?


https://reviews.llvm.org/D46135



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


[PATCH] D46135: [Driver, CodeGen] add options to enable/disable an FP cast optimization

2018-04-26 Thread Chandler Carruth via Phabricator via cfe-commits
chandlerc added inline comments.



Comment at: docs/UsersManual.rst:1260-1265
+   Enable or disable a code generation optimization that may convert a
+   cast of a floating-point value to integer and back to floating-point
+   into the equivalent of the math libary's 'trunc()' function. This
+   optimization is disabled by default to avoid problems associated
+   with relying on the undefined behavior of an overflowing cast, but 
+   that limitation should be considered temporary. 

spatel wrote:
> chandlerc wrote:
> > I would phrase this the other way around (and I think the flag name is 
> > already phrased the other way around?):
> > 
> > """
> > Enable a workaround for incorrect code that casts floating point values to 
> > integers where the floating point value is not representable in the integer 
> > type. This code is incorrect according to the language standard, but this 
> > flag will attempt to generate code to cause  > the flag enabled>.
> > """
> > 
> > Essentially, this should be more like '-fwrapv'. Also, I think the default 
> > should be what the specification says. People can explicitly pass this flag 
> > if their code is broken in this way.
> Ah - did I misinterpret the earlier comments? 
> 
> I thought we need to have the work-around 'on' by default as the immediate 
> fix for broken programs?
Maybe others feel strongly about the default. I'm happy to explicitly pass a 
flag for our code until we get it fixed here.

I would suggest starting by adding the flag to toggle the behavior but not 
changing the default (which as of now is 'optimize, no workaround') and then we 
can invert the default if we get enough feedback that this is causing users 
problems.

Either way, I'd word this as suggested above.


https://reviews.llvm.org/D46135



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


[PATCH] D46135: [Driver, CodeGen] add options to enable/disable an FP cast optimization

2018-04-26 Thread Steve Canon via Phabricator via cfe-commits
scanon added a comment.

I like Chandler's wording. Something like:

"... this flag will attempt to cause "


https://reviews.llvm.org/D46135



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


[PATCH] D46081: [analyzer] Expand conversion check to check more expressions for overflow and underflow

2018-04-26 Thread Paul Fultz II via Phabricator via cfe-commits
pfultz2 updated this revision to Diff 144202.
pfultz2 added a comment.

So I ran this on clang/llvm code base and fixed some false positives.


https://reviews.llvm.org/D46081

Files:
  lib/StaticAnalyzer/Checkers/ConversionChecker.cpp
  test/Analysis/conversion.c
  test/Analysis/conversion.cpp

Index: test/Analysis/conversion.cpp
===
--- /dev/null
+++ test/Analysis/conversion.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_analyze_cc1 -Wno-conversion -Wno-tautological-constant-compare -analyzer-checker=core,alpha.core.Conversion -verify %s
+
+// expected-no-diagnostics
+
+void dontwarn1() {
+  unsigned long x = static_cast(-1);
+}
+
+void dontwarn2(unsigned x) {
+  if (x == static_cast(-1)) {
+  }
+}
+
+struct C {
+  C(unsigned x, unsigned long y) {}
+};
+
+void f(C) {}
+
+void functioncall1(long x) {
+  f(C(64, x));
+}
Index: test/Analysis/conversion.c
===
--- test/Analysis/conversion.c
+++ test/Analysis/conversion.c
@@ -102,6 +102,23 @@
 S = U / S; // expected-warning {{Loss of sign}}
 }
 
+void f(unsigned x) {}
+void g(unsigned x) {}
+
+void functioncall1() {
+  long x = -1;
+  int y = 0;
+  f(x); // expected-warning {{Loss of sign in implicit conversion}}
+  f(y);
+}
+
+void functioncall2(int x, int y) {
+  if (x < 0)
+f(x); // expected-warning {{Loss of sign in implicit conversion}}
+  f(y);
+  f(x); // expected-warning {{Loss of sign in implicit conversion}}
+}
+
 void dontwarn1(unsigned U, signed S) {
   U8 = S; // It might be known that S is always 0x00-0xff.
   S8 = U; // It might be known that U is always 0x00-0xff.
@@ -129,14 +146,36 @@
   DOSTUFF;
 }
 
-// don't warn for calculations
-// seen some fp. For instance:  c2 = (c2 >= 'A' && c2 <= 'Z') ? c2 - 'A' + 'a' : c2;
-// there is a todo in the checker to handle calculations
 void dontwarn5() {
-  signed S = -32;
-  U8 = S + 10;
+  unsigned char c1 = 'A';
+  c1 = (c1 >= 'A' && c1 <= 'Z') ? c1 - 'A' + 'a' : c1;
+  unsigned char c2 = 0;
+  c2 = (c2 >= 'A' && c2 <= 'Z') ? c2 - 'A' + 'a' : c2;
+  unsigned char c3 = 'Z';
+  c3 = (c3 >= 'A' && c3 <= 'Z') ? c3 - 'A' + 'a' : c3;
+  unsigned char c4 = 'a';
+  c4 = (c4 >= 'A' && c4 <= 'Z') ? c4 - 'A' + 'a' : c4;
+  unsigned char c5 = '@';
+  c5 = (c5 >= 'A' && c5 <= 'Z') ? c5 - 'A' + 'a' : c5;
+}
+
+void dontwarn6() {
+  int x = ~0;
+  unsigned y = ~0;
 }
 
+void dontwarn7(unsigned x) {
+  if (x == (unsigned)-1) {
+  }
+}
+
+void dontwarn8() {
+  unsigned x = (unsigned)-1;
+}
+
+unsigned dontwarn9() {
+  return ~0;
+}
 
 // false positives..
 
Index: lib/StaticAnalyzer/Checkers/ConversionChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/ConversionChecker.cpp
+++ lib/StaticAnalyzer/Checkers/ConversionChecker.cpp
@@ -53,9 +53,8 @@
 
 void ConversionChecker::checkPreStmt(const ImplicitCastExpr *Cast,
  CheckerContext &C) const {
-  // TODO: For now we only warn about DeclRefExpr, to avoid noise. Warn for
-  // calculations also.
-  if (!isa(Cast->IgnoreParenImpCasts()))
+  // Don't warn for implicit conversions to bool
+  if (Cast->getType()->isBooleanType())
 return;
 
   // Don't warn for loss of sign/precision in macros.
@@ -67,16 +66,21 @@
   const Stmt *Parent = PM.getParent(Cast);
   if (!Parent)
 return;
+  // Dont warn if this is part of an explicit cast
+  if (isa(Parent))
+return;
 
   bool LossOfSign = false;
   bool LossOfPrecision = false;
 
   // Loss of sign/precision in binary operation.
   if (const auto *B = dyn_cast(Parent)) {
 BinaryOperator::Opcode Opc = B->getOpcode();
 if (Opc == BO_Assign) {
-  LossOfSign = isLossOfSign(Cast, C);
-  LossOfPrecision = isLossOfPrecision(Cast, Cast->getType(), C);
+  if (!Cast->IgnoreParenImpCasts()->isEvaluatable(C.getASTContext())) {
+LossOfSign = isLossOfSign(Cast, C);
+LossOfPrecision = isLossOfPrecision(Cast, Cast->getType(), C);
+  }
 } else if (Opc == BO_AddAssign || Opc == BO_SubAssign) {
   // No loss of sign.
   LossOfPrecision = isLossOfPrecision(Cast, B->getLHS()->getType(), C);
@@ -95,7 +99,12 @@
 } else if (B->isRelationalOp() || B->isMultiplicativeOp()) {
   LossOfSign = isLossOfSign(Cast, C);
 }
-  } else if (isa(Parent)) {
+  } else if (isa(Parent) || isa(Parent)) {
+if (!Cast->IgnoreParenImpCasts()->isEvaluatable(C.getASTContext())) {
+  LossOfSign = isLossOfSign(Cast, C);
+  LossOfPrecision = isLossOfPrecision(Cast, Cast->getType(), C);
+}
+  } else {
 LossOfSign = isLossOfSign(Cast, C);
 LossOfPrecision = isLossOfPrecision(Cast, Cast->getType(), C);
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46135: [Driver, CodeGen] add options to enable/disable an FP cast optimization

2018-04-26 Thread Sanjay Patel via Phabricator via cfe-commits
spatel updated this revision to Diff 144200.
spatel added a comment.

Patch updated:

1. Improve the documentation language - more suggestions welcome!
2. Change the default setting so the work-around is 'off' (ie, by default 
assume source is compliant and optimize accordingly).
3. Remove the 'no' version of the flag. Given the change in the default, this 
seems more natural to me, and it simplifies the patch/tests...but I might have 
been too pessimistic before and this is too optimistic? Let me know...


https://reviews.llvm.org/D46135

Files:
  docs/UsersManual.rst
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/CGCall.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/no-junk-ftrunc.c
  test/Driver/fast-math.c

Index: test/Driver/fast-math.c
===
--- test/Driver/fast-math.c
+++ test/Driver/fast-math.c
@@ -287,3 +287,17 @@
 // RUN: %clang -### -ftrapping-math -fno-trapping-math -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NO-TRAPPING-MATH %s
 // CHECK-NO-TRAPPING-MATH: "-fno-trapping-math"
+
+// This isn't fast-math, but the option is handled in the same place as other FP params.
+// The flag is *not* passed by default. 
+
+// RUN: %clang -### -ffp-cast-overflow-workaround -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-FPOV-WORKAROUND %s
+// CHECK-FPOV-WORKAROUND: "-cc1"
+// CHECK-FPOV-WORKAROUND: "-ffp-cast-overflow-workaround"
+
+// RUN: %clang -### -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-FPOV-WORKAROUND-DEFAULT %s
+// CHECK-FPOV-WORKAROUND-DEFAULT: "-cc1"
+// CHECK-FPOV-WORKAROUND-DEFAULT-NOT: "-ffp-cast-overflow-workaround"
+
Index: test/CodeGen/no-junk-ftrunc.c
===
--- test/CodeGen/no-junk-ftrunc.c
+++ test/CodeGen/no-junk-ftrunc.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -S -ffp-cast-overflow-workaround %s -emit-llvm -o - | FileCheck %s
+
+// CHECK-LABEL: main
+// CHECK: attributes #0 = {{.*}}"fp-cast-overflow-workaround"="true"{{.*}}
+
+int main() {
+  return 0;
+}
+
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -699,6 +699,8 @@
   Opts.Reciprocals = Args.getAllArgValues(OPT_mrecip_EQ);
   Opts.ReciprocalMath = Args.hasArg(OPT_freciprocal_math);
   Opts.NoTrappingMath = Args.hasArg(OPT_fno_trapping_math);
+  Opts.FPCastOverflowWorkaround = Args.hasArg(OPT_ffp_cast_overflow_workaround);
+
   Opts.NoZeroInitializedInBSS = Args.hasArg(OPT_mno_zero_initialized_in_bss);
   Opts.NumRegisterParameters = getLastArgIntValue(Args, OPT_mregparm, 0, Diags);
   Opts.NoExecStack = Args.hasArg(OPT_mno_exec_stack);
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -2241,6 +2241,10 @@
 CmdArgs.push_back("-mfpmath");
 CmdArgs.push_back(A->getValue());
   }
+
+  // Disable a codegen optimization for floating-point casts.
+  if (Args.hasArg(options::OPT_ffp_cast_overflow_workaround))
+CmdArgs.push_back("-ffp-cast-overflow-workaround");
 }
 
 static void RenderAnalyzerOptions(const ArgList &Args, ArgStringList &CmdArgs,
Index: lib/CodeGen/CGCall.cpp
===
--- lib/CodeGen/CGCall.cpp
+++ lib/CodeGen/CGCall.cpp
@@ -1727,6 +1727,9 @@
 FuncAttrs.addAttribute("no-trapping-math",
llvm::toStringRef(CodeGenOpts.NoTrappingMath));
 
+if (CodeGenOpts.FPCastOverflowWorkaround)
+  FuncAttrs.addAttribute("fp-cast-overflow-workaround", "true");
+
 // TODO: Are these all needed?
 // unsafe/inf/nan/nsz are handled by instruction-level FastMathFlags.
 FuncAttrs.addAttribute("no-infs-fp-math",
Index: include/clang/Frontend/CodeGenOptions.def
===
--- include/clang/Frontend/CodeGenOptions.def
+++ include/clang/Frontend/CodeGenOptions.def
@@ -136,6 +136,12 @@
 CODEGENOPT(NoNaNsFPMath  , 1, 0) ///< Assume FP arguments, results not NaN.
 CODEGENOPT(FlushDenorm   , 1, 0) ///< Allow FP denorm numbers to be flushed to zero
 CODEGENOPT(CorrectlyRoundedDivSqrt, 1, 0) ///< -cl-fp32-correctly-rounded-divide-sqrt
+
+/// Disable a float-to-int-to-float cast optimization. This attempts to generate
+/// code as if the result of an overflowing conversion matches the overflowing
+/// behavior of a target's native float-to-int conversion instructions.
+CODEGENOPT(FPCastOverflowWorkaround, 1, 0)
+
 CODEGENOPT(UniformWGSize , 1, 0) ///< -cl-uniform-work-group-size
 CODEGENOPT(NoZeroInitializedInBSS , 1, 0) ///< -fno-zero-initialized-in-bss.
 /// \brief Method of Objective-C dispatch to use.
Index: include/clang/Driver/Options.td
==

r330997 - [x86] Revert r330322 (& r330323): Lowering x86 adds/addus/subs/subus intrinsics

2018-04-26 Thread Chandler Carruth via cfe-commits
Author: chandlerc
Date: Thu Apr 26 14:46:01 2018
New Revision: 330997

URL: http://llvm.org/viewvc/llvm-project?rev=330997&view=rev
Log:
[x86] Revert r330322 (& r330323): Lowering x86 adds/addus/subs/subus intrinsics

The LLVM commit introduces a crash in LLVM's instruction selection.

I filed http://llvm.org/PR37260 with the test case.

Modified:
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/test/CodeGen/avx2-builtins.c
cfe/trunk/test/CodeGen/avx512bw-builtins.c
cfe/trunk/test/CodeGen/avx512vlbw-builtins.c
cfe/trunk/test/CodeGen/sse2-builtins.c

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=330997&r1=330996&r2=330997&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Thu Apr 26 14:46:01 2018
@@ -8449,76 +8449,6 @@ static Value *EmitX86SExtMask(CodeGenFun
   return CGF.Builder.CreateSExt(Mask, DstTy, "vpmovm2");
 }
 
-// Emit addition or subtraction with saturation.
-// Handles both signed and unsigned intrinsics.
-static Value *EmitX86AddSubSatExpr(CodeGenFunction &CGF, const CallExpr *E,
-   SmallVectorImpl &Ops,
-   bool IsAddition, bool Signed) {
-
-  // Collect vector elements and type data.
-  llvm::Type *ResultType = CGF.ConvertType(E->getType());
-  int NumElements = ResultType->getVectorNumElements();
-  Value *Res;
-  if (!IsAddition && !Signed) {
-Value *ICmp = CGF.Builder.CreateICmp(ICmpInst::ICMP_UGT, Ops[0], Ops[1]);
-Value *Select = CGF.Builder.CreateSelect(ICmp, Ops[0], Ops[1]);
-Res = CGF.Builder.CreateSub(Select, Ops[1]);
-  } else {
-unsigned EltSizeInBits = ResultType->getScalarSizeInBits();
-llvm::Type *ExtElementType = EltSizeInBits == 8 ?
- CGF.Builder.getInt16Ty() :
- CGF.Builder.getInt32Ty();
-
-// Extending vectors to next possible width to make space for possible
-// overflow.
-llvm::Type *ExtType = llvm::VectorType::get(ExtElementType, NumElements);
-Value *VecA = Signed ? CGF.Builder.CreateSExt(Ops[0], ExtType)
- : CGF.Builder.CreateZExt(Ops[0], ExtType);
-Value *VecB = Signed ? CGF.Builder.CreateSExt(Ops[1], ExtType)
- : CGF.Builder.CreateZExt(Ops[1], ExtType);
-
-llvm::Value *ExtProduct = IsAddition ? CGF.Builder.CreateAdd(VecA, VecB)
- : CGF.Builder.CreateSub(VecA, VecB);
-
-// Create vector of the same type as expected result with max possible
-// values and extend it to the same type as the product of the addition.
-APInt SignedMaxValue =
-llvm::APInt::getSignedMaxValue(EltSizeInBits);
-Value *Max = Signed ? llvm::ConstantInt::get(ResultType, SignedMaxValue)
-: llvm::Constant::getAllOnesValue(ResultType);
-Value *ExtMaxVec = Signed ? CGF.Builder.CreateSExt(Max, ExtType)
-  : CGF.Builder.CreateZExt(Max, ExtType);
-// In Product, replace all overflowed values with max values of 
non-extended
-// type.
-ICmpInst::Predicate Pred = Signed ? ICmpInst::ICMP_SLE : 
ICmpInst::ICMP_ULE;
-Value *Cmp = CGF.Builder.CreateICmp(Pred, ExtProduct,
-ExtMaxVec); // 1 if no overflow.
-Value *SaturatedProduct = CGF.Builder.CreateSelect(
-Cmp, ExtProduct, ExtMaxVec); // If overflowed, copy from max values.
-
-if (Signed) {
-  APInt SignedMinValue =
-  llvm::APInt::getSignedMinValue(EltSizeInBits);
-  Value *Min = llvm::ConstantInt::get(ResultType, SignedMinValue);
-  Value *ExtMinVec = CGF.Builder.CreateSExt(Min, ExtType);
-  Value *IsNegative =
-CGF.Builder.CreateICmp(ICmpInst::ICMP_SLT, SaturatedProduct, 
ExtMinVec);
-  SaturatedProduct =
-CGF.Builder.CreateSelect(IsNegative, ExtMinVec, SaturatedProduct);
-}
-
-Res = CGF.Builder.CreateTrunc(SaturatedProduct,
-  ResultType); // Trunc to ResultType.
-  }
-  if (E->getNumArgs() == 4) { // For masked intrinsics.
-Value *VecSRC = Ops[2];
-Value *Mask = Ops[3];
-return EmitX86Select(CGF, Mask, Res, VecSRC);
-  }
-
-  return Res;
-}
-
 Value *CodeGenFunction::EmitX86CpuIs(const CallExpr *E) {
   const Expr *CPUExpr = E->getArg(0)->IgnoreParenCasts();
   StringRef CPUStr = cast(CPUExpr)->getString();
@@ -9586,37 +9516,10 @@ Value *CodeGenFunction::EmitX86BuiltinEx
 Load->setVolatile(true);
 return Load;
   }
-  case X86::BI__builtin_ia32_paddusb512_mask:
-  case X86::BI__builtin_ia32_paddusw512_mask:
-  case X86::BI__builtin_ia32_paddusb256:
-  case X86::BI__builtin_ia32_paddusw256:
-  case X86::BI__builtin_ia32_paddusb128:
-  case X86::BI__builtin_ia32_paddusw128:
-return EmitX86AddSubSatExpr(*this, E, Ops, true,

[PATCH] D46135: [Driver, CodeGen] add options to enable/disable an FP cast optimization

2018-04-26 Thread Chandler Carruth via Phabricator via cfe-commits
chandlerc added a comment.

In https://reviews.llvm.org/D46135#1080108, @spatel wrote:

> 3. Remove the 'no' version of the flag. Given the change in the default, this 
> seems more natural to me, and it simplifies the patch/tests...but I might 
> have been too pessimistic before and this is too optimistic? Let me know...


Please keep the `no-` version so that the flag can be toggled by appending to 
the command line.




Comment at: test/CodeGen/no-junk-ftrunc.c:1
+// RUN: %clang_cc1 -S -ffp-cast-overflow-workaround %s -emit-llvm -o - | 
FileCheck %s
+

spatel wrote:
> lebedev.ri wrote:
> > For a good measure, i'd add one more `RUN` line to test that it is 
> > currently the default.
> > (Yes, i noticed that it is already tested in `test/Driver/fast-math.c`)
> The driver alone is handling the default setting, so it passes this flag to 
> the front-end only when we're going to disable the transform. Ie, the driver 
> eats "-fno-fp-cast-overflow-workaround" and sends nothing in that case to the 
> front-end. 
> 
> So there's not currently any case where the function attribute will be 
> "fp-cast-overflow-workaround=false", but I left that as a possibility in case 
> we decide to lift the limit at a finer granularity (scalar vs. vector etc).
> 
> I may be misunderstanding the question/suggestion - do we want the front-end 
> to independently have a default setting?
How about a test that checks the attribute is *absent* in the default mode then?

I think it's useful to have the both sides of the test, however a particular 
side is spelled.


https://reviews.llvm.org/D46135



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


[PATCH] D46115: [ASTImporter] properly import SrcLoc of Attr

2018-04-26 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a reviewer: a.sidorin.
NoQ added a comment.

+Alexey because he's the `ASTImporter` guy.


Repository:
  rC Clang

https://reviews.llvm.org/D46115



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


[PATCH] D46146: [analyzer] pr37152: Fix operator delete[] array-type-sub-expression handling.

2018-04-26 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ created this revision.
NoQ added reviewers: dcoughlin, xazax.hun, a.sidorin, george.karpenkov, szepet.
Herald added subscribers: cfe-commits, rnkovacs, baloghadamsoftware.

When operator `delete[]` receives a sub-expression of array type, it destroys 
the array correctly. Even if it's multi-dimensional, simply because in this 
case it's an array of array-type objects and destroying such array would mean 
properly destroying each object, where the object itself is an array, so 
properly destroying it means destroying its objects, etc.

In this case the AST is saying that the destroyed type is an array type - and 
we weren't prepared for that.

For now there's no actual calling multiple destructors; at least we're trying 
not to crash.


Repository:
  rC Clang

https://reviews.llvm.org/D46146

Files:
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  test/Analysis/new.cpp


Index: test/Analysis/new.cpp
===
--- test/Analysis/new.cpp
+++ test/Analysis/new.cpp
@@ -274,6 +274,24 @@
   clang_analyzer_eval(true); // expected-warning{{TRUE}}
 }
 
+void test_array_delete() {
+  class C {
+  public:
+~C() {}
+  };
+
+  auto c1 = new C[2][3];
+  delete[] c1; // no-crash // no-warning
+
+  C c2[4];
+  // FIXME: Should warn.
+  delete[] &c2; // no-crash
+
+  C c3[7][6];
+  // FIXME: Should warn.
+  delete[] &c3; // no-crash
+}
+
 void testDeleteNull() {
   NoReturnDtor *foo = 0;
   delete foo; // should not call destructor, checked below
Index: lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -1086,12 +1086,14 @@
 // This workaround will just run the first destructor (which will still
 // invalidate the entire array).
 CallOpts.IsArrayCtorOrDtor = true;
+// Yes, it may even be a multi-dimensional array.
+while (const auto *AT = getContext().getAsArrayType(DTy))
+  DTy = AT->getElementType();
 if (ArgR)
   ArgR = getStoreManager().GetElementZeroRegion(cast(ArgR), 
DTy);
   }
 
-  VisitCXXDestructor(DE->getDestroyedType(), ArgR, DE, /*IsBase=*/false,
- Pred, Dst, CallOpts);
+  VisitCXXDestructor(DTy, ArgR, DE, /*IsBase=*/false, Pred, Dst, CallOpts);
 }
 
 void ExprEngine::ProcessBaseDtor(const CFGBaseDtor D,


Index: test/Analysis/new.cpp
===
--- test/Analysis/new.cpp
+++ test/Analysis/new.cpp
@@ -274,6 +274,24 @@
   clang_analyzer_eval(true); // expected-warning{{TRUE}}
 }
 
+void test_array_delete() {
+  class C {
+  public:
+~C() {}
+  };
+
+  auto c1 = new C[2][3];
+  delete[] c1; // no-crash // no-warning
+
+  C c2[4];
+  // FIXME: Should warn.
+  delete[] &c2; // no-crash
+
+  C c3[7][6];
+  // FIXME: Should warn.
+  delete[] &c3; // no-crash
+}
+
 void testDeleteNull() {
   NoReturnDtor *foo = 0;
   delete foo; // should not call destructor, checked below
Index: lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -1086,12 +1086,14 @@
 // This workaround will just run the first destructor (which will still
 // invalidate the entire array).
 CallOpts.IsArrayCtorOrDtor = true;
+// Yes, it may even be a multi-dimensional array.
+while (const auto *AT = getContext().getAsArrayType(DTy))
+  DTy = AT->getElementType();
 if (ArgR)
   ArgR = getStoreManager().GetElementZeroRegion(cast(ArgR), DTy);
   }
 
-  VisitCXXDestructor(DE->getDestroyedType(), ArgR, DE, /*IsBase=*/false,
- Pred, Dst, CallOpts);
+  VisitCXXDestructor(DTy, ArgR, DE, /*IsBase=*/false, Pred, Dst, CallOpts);
 }
 
 void ExprEngine::ProcessBaseDtor(const CFGBaseDtor D,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46146: [analyzer] pr37152: Fix operator delete[] array-type-sub-expression handling.

2018-04-26 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added inline comments.



Comment at: lib/StaticAnalyzer/Core/ExprEngine.cpp:1089-1091
+// Yes, it may even be a multi-dimensional array.
+while (const auto *AT = getContext().getAsArrayType(DTy))
+  DTy = AT->getElementType();

Maybe add a FIXME to model multiple destructor calls?


Repository:
  rC Clang

https://reviews.llvm.org/D46146



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


[PATCH] D46148: [CUDA] Added -f[no-]cuda-short-ptr option

2018-04-26 Thread Artem Belevich via Phabricator via cfe-commits
tra created this revision.
tra added a reviewer: jlebar.
Herald added subscribers: bixia, sanjoy, jholewinski.

The option enables use of 32-bit pointers for accessing
const/local/shared memory. The feature is disabled by default.


https://reviews.llvm.org/D46148

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Targets/NVPTX.cpp
  clang/lib/Driver/ToolChains/Cuda.cpp


Index: clang/lib/Driver/ToolChains/Cuda.cpp
===
--- clang/lib/Driver/ToolChains/Cuda.cpp
+++ clang/lib/Driver/ToolChains/Cuda.cpp
@@ -633,8 +633,10 @@
 // CUDA-9.0 uses new instructions that are only available in PTX6.0+
 PtxFeature = "+ptx60";
   }
-  CC1Args.push_back("-target-feature");
-  CC1Args.push_back(PtxFeature);
+  CC1Args.append({"-target-feature", PtxFeature});
+  if (DriverArgs.hasFlag(options::OPT_fcuda_short_ptr,
+ options::OPT_fno_cuda_short_ptr, false))
+CC1Args.append({"-target-feature", "+short-ptr"});
 
   if (DeviceOffloadingKind == Action::OFK_OpenMP) {
 SmallVector LibraryPaths;
Index: clang/lib/Basic/Targets/NVPTX.cpp
===
--- clang/lib/Basic/Targets/NVPTX.cpp
+++ clang/lib/Basic/Targets/NVPTX.cpp
@@ -41,7 +41,11 @@
  "NVPTX only supports 32- and 64-bit modes.");
 
   PTXVersion = 32;
+  bool UseShortPtr = false;
   for (const StringRef Feature : Opts.FeaturesAsWritten) {
+llvm::errs() << "F: " << Feature << "\n";
+if (Feature == "+short-ptr")
+  UseShortPtr = true;
 if (!Feature.startswith("+ptx"))
   continue;
 PTXVersion = llvm::StringSwitch(Feature)
@@ -68,6 +72,9 @@
 
   if (TargetPointerWidth == 32)
 resetDataLayout("e-p:32:32-i64:64-i128:128-v16:16-v32:32-n16:32:64");
+  else if (UseShortPtr)
+resetDataLayout(
+
"e-p3:32:32-p4:32:32-p5:32:32-i64:64-i128:128-v16:16-v32:32-n16:32:64");
   else
 resetDataLayout("e-i64:64-i128:128-v16:16-v32:32-n16:32:64");
 
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -579,6 +579,9 @@
 def fcuda_rdc : Flag<["-"], "fcuda-rdc">, Flags<[CC1Option]>,
   HelpText<"Generate relocatable device code, also known as separate 
compilation mode.">;
 def fno_cuda_rdc : Flag<["-"], "fno-cuda-rdc">;
+def fcuda_short_ptr : Flag<["-"], "fcuda-short-ptr">, Flags<[CC1Option]>,
+  HelpText<"Use 32-bit pointers for accessing const/local/shared address 
spaces.">;
+def fno_cuda_short_ptr : Flag<["-"], "fno-cuda-short-ptr">;
 def dA : Flag<["-"], "dA">, Group;
 def dD : Flag<["-"], "dD">, Group, Flags<[CC1Option]>,
   HelpText<"Print macro definitions in -E mode in addition to normal output">;


Index: clang/lib/Driver/ToolChains/Cuda.cpp
===
--- clang/lib/Driver/ToolChains/Cuda.cpp
+++ clang/lib/Driver/ToolChains/Cuda.cpp
@@ -633,8 +633,10 @@
 // CUDA-9.0 uses new instructions that are only available in PTX6.0+
 PtxFeature = "+ptx60";
   }
-  CC1Args.push_back("-target-feature");
-  CC1Args.push_back(PtxFeature);
+  CC1Args.append({"-target-feature", PtxFeature});
+  if (DriverArgs.hasFlag(options::OPT_fcuda_short_ptr,
+ options::OPT_fno_cuda_short_ptr, false))
+CC1Args.append({"-target-feature", "+short-ptr"});
 
   if (DeviceOffloadingKind == Action::OFK_OpenMP) {
 SmallVector LibraryPaths;
Index: clang/lib/Basic/Targets/NVPTX.cpp
===
--- clang/lib/Basic/Targets/NVPTX.cpp
+++ clang/lib/Basic/Targets/NVPTX.cpp
@@ -41,7 +41,11 @@
  "NVPTX only supports 32- and 64-bit modes.");
 
   PTXVersion = 32;
+  bool UseShortPtr = false;
   for (const StringRef Feature : Opts.FeaturesAsWritten) {
+llvm::errs() << "F: " << Feature << "\n";
+if (Feature == "+short-ptr")
+  UseShortPtr = true;
 if (!Feature.startswith("+ptx"))
   continue;
 PTXVersion = llvm::StringSwitch(Feature)
@@ -68,6 +72,9 @@
 
   if (TargetPointerWidth == 32)
 resetDataLayout("e-p:32:32-i64:64-i128:128-v16:16-v32:32-n16:32:64");
+  else if (UseShortPtr)
+resetDataLayout(
+"e-p3:32:32-p4:32:32-p5:32:32-i64:64-i128:128-v16:16-v32:32-n16:32:64");
   else
 resetDataLayout("e-i64:64-i128:128-v16:16-v32:32-n16:32:64");
 
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -579,6 +579,9 @@
 def fcuda_rdc : Flag<["-"], "fcuda-rdc">, Flags<[CC1Option]>,
   HelpText<"Generate relocatable device code, also known as separate compilation mode.">;
 def fno_cuda_rdc : Flag<["-"], "fno-cuda-rdc">;
+def fcuda_short_ptr : Flag<["-"], "fcuda-short-ptr">, Flags<[CC1Option]>,
+  HelpText<"Use 32-bit pointers for acc

[libcxx] r330999 - [libcxx] [test] Remove non-portable assertions from filebuf tests

2018-04-26 Thread Billy Robert O'Neal III via cfe-commits
Author: bion
Date: Thu Apr 26 15:18:33 2018
New Revision: 330999

URL: http://llvm.org/viewvc/llvm-project?rev=330999&view=rev
Log:
[libcxx] [test] Remove non-portable assertions from filebuf tests

seekoff.pass.cpp:
libc++'s tests are asserting things about the buffer passed to pubsetbuf. 
[filebuf.virtuals]/12 says that what the filebuf does with the buffer you give 
it is completely implementation defined. The MSVC++ implementation takes that 
buffer and hands it off to the CRT (by calling ::setvbuf) and the CRT doesn't 
necessarily follow the pattern this test wants.
This change simply makes asserts against the buffer's contents use 
LIBCPP_ASSERT instead of assert.

pbackfail.pass.cpp:
libc++'s tests are asserting about what characters will and will not be 
available in the putback area. [filebuf.virtuals]/9 says "The function can 
alter the number of putback positions available as a result of any call." This 
change LIBCPP_ASSERTS libc++'s behavior, but checks invariants of the putback 
area independently.

Modified:

libcxx/trunk/test/std/input.output/file.streams/fstreams/filebuf.virtuals/pbackfail.pass.cpp

libcxx/trunk/test/std/input.output/file.streams/fstreams/filebuf.virtuals/seekoff.pass.cpp

Modified: 
libcxx/trunk/test/std/input.output/file.streams/fstreams/filebuf.virtuals/pbackfail.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/input.output/file.streams/fstreams/filebuf.virtuals/pbackfail.pass.cpp?rev=330999&r1=330998&r2=330999&view=diff
==
--- 
libcxx/trunk/test/std/input.output/file.streams/fstreams/filebuf.virtuals/pbackfail.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/input.output/file.streams/fstreams/filebuf.virtuals/pbackfail.pass.cpp
 Thu Apr 26 15:18:33 2018
@@ -11,11 +11,11 @@
 
 // int_type pbackfail(int_type c = traits::eof());
 
-// This test is not entirely portable
-
 #include 
 #include 
 
+#include "test_macros.h"
+
 template 
 struct test_buf
 : public std::basic_filebuf
@@ -41,7 +41,12 @@ int main()
 assert(f.is_open());
 assert(f.sbumpc() == '1');
 assert(f.sgetc() == '2');
-assert(f.pbackfail('a') == -1);
+typename test_buf::int_type pbackResult = f.pbackfail('a');
+LIBCPP_ASSERT(pbackResult == -1);
+if (pbackResult != -1) {
+assert(f.sbumpc() == 'a');
+assert(f.sgetc() == '2');
+}
 }
 {
 test_buf f;
@@ -49,8 +54,11 @@ int main()
 assert(f.is_open());
 assert(f.sbumpc() == '1');
 assert(f.sgetc() == '2');
-assert(f.pbackfail('a') == 'a');
-assert(f.sbumpc() == 'a');
-assert(f.sgetc() == '2');
+typename test_buf::int_type pbackResult = f.pbackfail('a');
+LIBCPP_ASSERT(pbackResult == 'a');
+if (pbackResult != -1) {
+assert(f.sbumpc() == 'a');
+assert(f.sgetc() == '2');
+}
 }
 }

Modified: 
libcxx/trunk/test/std/input.output/file.streams/fstreams/filebuf.virtuals/seekoff.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/input.output/file.streams/fstreams/filebuf.virtuals/seekoff.pass.cpp?rev=330999&r1=330998&r2=330999&view=diff
==
--- 
libcxx/trunk/test/std/input.output/file.streams/fstreams/filebuf.virtuals/seekoff.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/input.output/file.streams/fstreams/filebuf.virtuals/seekoff.pass.cpp
 Thu Apr 26 15:18:33 2018
@@ -14,11 +14,11 @@
 // pos_type seekpos(pos_type sp,
 //  ios_base::openmode which = ios_base::in | ios_base::out);
 
-// This test is not entirely portable
-
 #include 
 #include 
 
+#include "test_macros.h"
+
 int main()
 {
 {
@@ -30,7 +30,7 @@ int main()
| std::ios_base::trunc) 
!= 0);
 assert(f.is_open());
 f.sputn("abcdefghijklmnopqrstuvwxyz", 26);
-assert(buf[0] == 'v');
+LIBCPP_ASSERT(buf[0] == 'v');
 pos_type p = f.pubseekoff(-15, std::ios_base::cur);
 assert(p == 11);
 assert(f.sgetc() == 'l');
@@ -51,7 +51,7 @@ int main()
| std::ios_base::trunc) 
!= 0);
 assert(f.is_open());
 f.sputn(L"abcdefghijklmnopqrstuvwxyz", 26);
-assert(buf[0] == L'v');
+LIBCPP_ASSERT(buf[0] == L'v');
 pos_type p = f.pubseekoff(-15, std::ios_base::cur);
 assert(p == 11);
 assert(f.sgetc() == L'l');


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


[PATCH] D46148: [CUDA] Added -f[no-]cuda-short-ptr option

2018-04-26 Thread Artem Belevich via Phabricator via cfe-commits
tra updated this revision to Diff 144216.
tra added a comment.

Removed debug printout.


https://reviews.llvm.org/D46148

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Targets/NVPTX.cpp
  clang/lib/Driver/ToolChains/Cuda.cpp


Index: clang/lib/Driver/ToolChains/Cuda.cpp
===
--- clang/lib/Driver/ToolChains/Cuda.cpp
+++ clang/lib/Driver/ToolChains/Cuda.cpp
@@ -633,8 +633,10 @@
 // CUDA-9.0 uses new instructions that are only available in PTX6.0+
 PtxFeature = "+ptx60";
   }
-  CC1Args.push_back("-target-feature");
-  CC1Args.push_back(PtxFeature);
+  CC1Args.append({"-target-feature", PtxFeature});
+  if (DriverArgs.hasFlag(options::OPT_fcuda_short_ptr,
+ options::OPT_fno_cuda_short_ptr, false))
+CC1Args.append({"-target-feature", "+short-ptr"});
 
   if (DeviceOffloadingKind == Action::OFK_OpenMP) {
 SmallVector LibraryPaths;
Index: clang/lib/Basic/Targets/NVPTX.cpp
===
--- clang/lib/Basic/Targets/NVPTX.cpp
+++ clang/lib/Basic/Targets/NVPTX.cpp
@@ -41,19 +41,21 @@
  "NVPTX only supports 32- and 64-bit modes.");
 
   PTXVersion = 32;
+  bool UseShortPtr = false;
   for (const StringRef Feature : Opts.FeaturesAsWritten) {
-if (!Feature.startswith("+ptx"))
-  continue;
-PTXVersion = llvm::StringSwitch(Feature)
- .Case("+ptx61", 61)
- .Case("+ptx60", 60)
- .Case("+ptx50", 50)
- .Case("+ptx43", 43)
- .Case("+ptx42", 42)
- .Case("+ptx41", 41)
- .Case("+ptx40", 40)
- .Case("+ptx32", 32)
- .Default(32);
+if (Feature == "+short-ptr")
+  UseShortPtr = true;
+else if (Feature.startswith("+ptx"))
+  PTXVersion = llvm::StringSwitch(Feature)
+   .Case("+ptx61", 61)
+   .Case("+ptx60", 60)
+   .Case("+ptx50", 50)
+   .Case("+ptx43", 43)
+   .Case("+ptx42", 42)
+   .Case("+ptx41", 41)
+   .Case("+ptx40", 40)
+   .Case("+ptx32", 32)
+   .Default(32);
   }
 
   TLSSupported = false;
@@ -68,6 +70,9 @@
 
   if (TargetPointerWidth == 32)
 resetDataLayout("e-p:32:32-i64:64-i128:128-v16:16-v32:32-n16:32:64");
+  else if (UseShortPtr)
+resetDataLayout(
+
"e-p3:32:32-p4:32:32-p5:32:32-i64:64-i128:128-v16:16-v32:32-n16:32:64");
   else
 resetDataLayout("e-i64:64-i128:128-v16:16-v32:32-n16:32:64");
 
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -579,6 +579,9 @@
 def fcuda_rdc : Flag<["-"], "fcuda-rdc">, Flags<[CC1Option]>,
   HelpText<"Generate relocatable device code, also known as separate 
compilation mode.">;
 def fno_cuda_rdc : Flag<["-"], "fno-cuda-rdc">;
+def fcuda_short_ptr : Flag<["-"], "fcuda-short-ptr">, Flags<[CC1Option]>,
+  HelpText<"Use 32-bit pointers for accessing const/local/shared address 
spaces.">;
+def fno_cuda_short_ptr : Flag<["-"], "fno-cuda-short-ptr">;
 def dA : Flag<["-"], "dA">, Group;
 def dD : Flag<["-"], "dD">, Group, Flags<[CC1Option]>,
   HelpText<"Print macro definitions in -E mode in addition to normal output">;


Index: clang/lib/Driver/ToolChains/Cuda.cpp
===
--- clang/lib/Driver/ToolChains/Cuda.cpp
+++ clang/lib/Driver/ToolChains/Cuda.cpp
@@ -633,8 +633,10 @@
 // CUDA-9.0 uses new instructions that are only available in PTX6.0+
 PtxFeature = "+ptx60";
   }
-  CC1Args.push_back("-target-feature");
-  CC1Args.push_back(PtxFeature);
+  CC1Args.append({"-target-feature", PtxFeature});
+  if (DriverArgs.hasFlag(options::OPT_fcuda_short_ptr,
+ options::OPT_fno_cuda_short_ptr, false))
+CC1Args.append({"-target-feature", "+short-ptr"});
 
   if (DeviceOffloadingKind == Action::OFK_OpenMP) {
 SmallVector LibraryPaths;
Index: clang/lib/Basic/Targets/NVPTX.cpp
===
--- clang/lib/Basic/Targets/NVPTX.cpp
+++ clang/lib/Basic/Targets/NVPTX.cpp
@@ -41,19 +41,21 @@
  "NVPTX only supports 32- and 64-bit modes.");
 
   PTXVersion = 32;
+  bool UseShortPtr = false;
   for (const StringRef Feature : Opts.FeaturesAsWritten) {
-if (!Feature.startswith("+ptx"))
-  continue;
-PTXVersion = llvm::StringSwitch(Feature)
- .Case("+ptx61", 61)
- .Case("+ptx60", 60)
- .Case("+ptx50", 50)
- .Case("+ptx43", 43)
- .Case("+ptx42", 42)
- .Case("+ptx41", 41)
- .Case("

[PATCH] D45294: [libcxx] [test] Remove non-portable assertions from filebuf tests

2018-04-26 Thread Billy Robert O'Neal III via Phabricator via cfe-commits
BillyONeal closed this revision.
BillyONeal added a comment.

D:\msvc\src\qa\VC\Libs\libcxx\upstream>git svn dcommit
Committing to https://llvm.org/svn/llvm-project/libcxx/trunk ...
Use of uninitialized value $rec in scalar chomp at /mingw64/share/perl5/Git.pm 
line 557, <$fh> chunk 4.
Authentication realm: https://llvm.org:443 LLVM Subversion repository
Password for 'bion':

  M   
test/std/input.output/file.streams/fstreams/filebuf.virtuals/pbackfail.pass.cpp
  M   
test/std/input.output/file.streams/fstreams/filebuf.virtuals/seekoff.pass.cpp

Committed r330999

  M   
test/std/input.output/file.streams/fstreams/filebuf.virtuals/pbackfail.pass.cpp
  M   
test/std/input.output/file.streams/fstreams/filebuf.virtuals/seekoff.pass.cpp

r330999 = dc3bb72e3c9a47ef62d6288f73d164d3ba5fe941 (refs/remotes/llvm/master)
No changes between 706a727f5b068a7b5c6f43028cdbaf6ea610abe6 and 
refs/remotes/llvm/master
Resetting to the latest refs/remotes/llvm/master

D:\msvc\src\qa\VC\Libs\libcxx\upstream>


https://reviews.llvm.org/D45294



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


[PATCH] D46135: [Driver, CodeGen] add options to enable/disable an FP cast optimization

2018-04-26 Thread Sanjay Patel via Phabricator via cfe-commits
spatel updated this revision to Diff 144226.
spatel added a comment.

Patch upated:

1. Restore the 'no' option to allow toggling.
2. Add a RUN to the codegen test to show that the function attribute is not 
appended by default.


https://reviews.llvm.org/D46135

Files:
  docs/UsersManual.rst
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/CGCall.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/no-junk-ftrunc.c
  test/Driver/fast-math.c

Index: test/Driver/fast-math.c
===
--- test/Driver/fast-math.c
+++ test/Driver/fast-math.c
@@ -287,3 +287,27 @@
 // RUN: %clang -### -ftrapping-math -fno-trapping-math -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NO-TRAPPING-MATH %s
 // CHECK-NO-TRAPPING-MATH: "-fno-trapping-math"
+
+// This isn't fast-math, but the option is handled in the same place as other FP params.
+// Last option wins, and the flag is *not* passed by default. 
+
+// RUN: %clang -### -ffp-cast-overflow-workaround -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-FPOV-WORKAROUND %s
+// CHECK-FPOV-WORKAROUND: "-cc1"
+// CHECK-FPOV-WORKAROUND: "-ffp-cast-overflow-workaround"
+
+// RUN: %clang -### -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-FPOV-WORKAROUND-DEFAULT %s
+// CHECK-FPOV-WORKAROUND-DEFAULT: "-cc1"
+// CHECK-FPOV-WORKAROUND-DEFAULT-NOT: "-ffp-cast-overflow-workaround"
+
+// RUN: %clang -### -fno-fp-cast-overflow-workaround -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NO-FPOV-WORKAROUND %s
+// CHECK-NO-FPOV-WORKAROUND: "-cc1"
+// CHECK-NO-FPOV-WORKAROUND-NOT: "-ffp-cast-overflow-workaround"
+
+// RUN: %clang -### -ffp-cast-overflow-workaround -fno-fp-cast-overflow-workaround -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NO-FPOV-WORKAROUND-OVERRIDE %s
+// CHECK-NO-FPOV-WORKAROUND-OVERRIDE: "-cc1"
+// CHECK-NO-FPOV-WORKAROUND-OVERRIDE-NOT: "-ffp-cast-overflow-workaround"
+
Index: test/CodeGen/no-junk-ftrunc.c
===
--- test/CodeGen/no-junk-ftrunc.c
+++ test/CodeGen/no-junk-ftrunc.c
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -S -ffp-cast-overflow-workaround %s -emit-llvm -o - | FileCheck %s
+// CHECK-LABEL: main
+// CHECK: attributes #0 = {{.*}}"fp-cast-overflow-workaround"="true"{{.*}}
+
+// The workaround attribute is not applied by default.
+
+// RUN: %clang_cc1 -S %s -emit-llvm -o - | FileCheck %s --check-prefix=DEFAULT
+// DEFAULT-LABEL: main
+// DEFAULT-NOT: fp-cast-overflow-workaround
+
+int main() {
+  return 0;
+}
+
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -699,6 +699,8 @@
   Opts.Reciprocals = Args.getAllArgValues(OPT_mrecip_EQ);
   Opts.ReciprocalMath = Args.hasArg(OPT_freciprocal_math);
   Opts.NoTrappingMath = Args.hasArg(OPT_fno_trapping_math);
+  Opts.FPCastOverflowWorkaround = Args.hasArg(OPT_ffp_cast_overflow_workaround);
+
   Opts.NoZeroInitializedInBSS = Args.hasArg(OPT_mno_zero_initialized_in_bss);
   Opts.NumRegisterParameters = getLastArgIntValue(Args, OPT_mregparm, 0, Diags);
   Opts.NoExecStack = Args.hasArg(OPT_mno_exec_stack);
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -2241,6 +2241,11 @@
 CmdArgs.push_back("-mfpmath");
 CmdArgs.push_back(A->getValue());
   }
+
+  // Disable a codegen optimization for floating-point casts.
+  if (Args.hasFlag(options::OPT_ffp_cast_overflow_workaround,
+   options::OPT_fno_fp_cast_overflow_workaround, false))
+CmdArgs.push_back("-ffp-cast-overflow-workaround");
 }
 
 static void RenderAnalyzerOptions(const ArgList &Args, ArgStringList &CmdArgs,
Index: lib/CodeGen/CGCall.cpp
===
--- lib/CodeGen/CGCall.cpp
+++ lib/CodeGen/CGCall.cpp
@@ -1727,6 +1727,9 @@
 FuncAttrs.addAttribute("no-trapping-math",
llvm::toStringRef(CodeGenOpts.NoTrappingMath));
 
+if (CodeGenOpts.FPCastOverflowWorkaround)
+  FuncAttrs.addAttribute("fp-cast-overflow-workaround", "true");
+
 // TODO: Are these all needed?
 // unsafe/inf/nan/nsz are handled by instruction-level FastMathFlags.
 FuncAttrs.addAttribute("no-infs-fp-math",
Index: include/clang/Frontend/CodeGenOptions.def
===
--- include/clang/Frontend/CodeGenOptions.def
+++ include/clang/Frontend/CodeGenOptions.def
@@ -136,6 +136,12 @@
 CODEGENOPT(NoNaNsFPMath  , 1, 0) ///< Assume FP arguments, results not NaN.
 CODEGENOPT(FlushDenorm   , 1, 0) ///< Allow FP denorm numbers to be flushed to zero
 CODEGENOPT(CorrectlyRoundedDivSqrt, 1, 0) ///< -cl-fp32-correctly-r

[PATCH] D46146: [analyzer] pr37152: Fix operator delete[] array-type-sub-expression handling.

2018-04-26 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: lib/StaticAnalyzer/Core/ExprEngine.cpp:1089-1091
+// Yes, it may even be a multi-dimensional array.
+while (const auto *AT = getContext().getAsArrayType(DTy))
+  DTy = AT->getElementType();

alexfh wrote:
> Maybe add a FIXME to model multiple destructor calls?
Yep, we already have one a few lines above, for all kinds of destructors. The 
new code is not about supporting array delete in general; it's about supporting 
the situation when the sub-//expression// of the delete operator is of an array 
type, so there's nothing new here with respect to actually calling multiple 
destructors.


Repository:
  rC Clang

https://reviews.llvm.org/D46146



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


[PATCH] D45382: [CodeGen] Avoid destructing a struct type that has already been destructed by a delegated constructor

2018-04-26 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 144231.
ahatanak marked an inline comment as done.
ahatanak added a comment.

Rename variable to something OldCleanupScopeDepth.


Repository:
  rC Clang

https://reviews.llvm.org/D45382

Files:
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CGCleanup.cpp
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CodeGenFunction.h
  test/CodeGenObjCXX/arc-forwarded-lambda-call.mm
  test/CodeGenObjCXX/arc-special-member-functions.mm
  test/CodeGenObjCXX/lambda-expressions.mm

Index: test/CodeGenObjCXX/lambda-expressions.mm
===
--- test/CodeGenObjCXX/lambda-expressions.mm
+++ test/CodeGenObjCXX/lambda-expressions.mm
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10.0.0 -emit-llvm -o - %s -fexceptions -std=c++11 -fblocks -fobjc-arc | FileCheck -check-prefix=ARC %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10.0.0 -emit-llvm -o - %s -fexceptions -std=c++11 -fblocks -fobjc-arc -fobjc-runtime-has-weak -DWEAK_SUPPORTED | FileCheck -check-prefix=ARC %s
 // RUN: %clang_cc1 -triple x86_64-apple-darwin10.0.0 -emit-llvm -o - %s -fexceptions -std=c++11 -fblocks | FileCheck -check-prefix=MRC %s
 
 typedef int (^fp)();
@@ -138,5 +138,31 @@
 }
 @end
 
+// Check that the delegating invoke function doesn't destruct the Weak object
+// that is passed.
+
+// ARC-LABEL: define internal void @"_ZZN14LambdaDelegate4testEvEN3$_58__invokeENS_4WeakE"(
+// ARC: call void @"_ZZN14LambdaDelegate4testEvENK3$_5clENS_4WeakE"(
+// ARC-NEXT: ret void
+
+// ARC-LABEL: define internal void @"_ZZN14LambdaDelegate4testEvENK3$_5clENS_4WeakE"(
+// ARC: call void @_ZN14LambdaDelegate4WeakD1Ev(
+
+#ifdef WEAK_SUPPORTED
+
+namespace LambdaDelegate {
+
+struct Weak {
+  __weak id x;
+};
+
+void test() {
+  void (*p)(Weak) = [](Weak a) { };
+}
+
+};
+
+#endif
+
 // ARC: attributes [[NUW]] = { noinline nounwind{{.*}} }
 // MRC: attributes [[NUW]] = { noinline nounwind{{.*}} }
Index: test/CodeGenObjCXX/arc-special-member-functions.mm
===
--- test/CodeGenObjCXX/arc-special-member-functions.mm
+++ test/CodeGenObjCXX/arc-special-member-functions.mm
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fobjc-arc -fblocks -triple x86_64-apple-darwin10.0.0 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -std=c++11 -fobjc-arc -fblocks -triple x86_64-apple-darwin10.0.0 -fobjc-runtime-has-weak -emit-llvm -o - %s | FileCheck %s
 
 struct ObjCMember {
   id member;
@@ -12,6 +12,59 @@
   int (^bp)(int);
 };
 
+// CHECK: %[[STRUCT_CONTAINSWEAK:.*]] = type { %[[STRUCT_WEAK:.*]] }
+// CHECK: %[[STRUCT_WEAK]] = type { i8* }
+
+// The Weak object that is passed is destructed in this constructor.
+
+// CHECK: define void @_ZN12ContainsWeakC2E4Weak(
+// CHECK: call void @_ZN4WeakC1ERKS_(
+// CHECK: call void @_ZN4WeakD1Ev(
+
+// Check that the Weak object passed to this constructor is not destructed after
+// the delegate constructor is called.
+
+// CHECK: define void @_ZN12ContainsWeakC1E4Weak(
+// CHECK: call void @_ZN12ContainsWeakC2E4Weak(
+// CHECK-NEXT: ret void
+
+struct Weak {
+  Weak(id);
+  __weak id x;
+};
+
+struct ContainsWeak {
+  ContainsWeak(Weak);
+  Weak w;
+};
+
+ContainsWeak::ContainsWeak(Weak a) : w(a) {}
+
+// The Weak object that is passed is destructed in this constructor.
+
+// CHECK: define void @_ZN4BaseC2E4Weak(
+// CHECK: call void @_ZN4WeakD1Ev(
+// CHECK: ret void
+
+// Check that the Weak object passed to this constructor is not destructed after
+// the delegate constructor is called.
+
+// CHECK: define linkonce_odr void @_ZN7DerivedCI14BaseE4Weak(
+// CHECK: call void @_ZN7DerivedCI24BaseE4Weak(
+// CHECK-NEXT: ret void
+
+struct Base {
+  Base(Weak);
+};
+
+Base::Base(Weak a) {}
+
+struct Derived : Base {
+  using Base::Base;
+};
+
+Derived d(Weak(0));
+
 // CHECK-LABEL: define void @_Z42test_ObjCMember_default_construct_destructv(
 void test_ObjCMember_default_construct_destruct() {
   // CHECK: call void @_ZN10ObjCMemberC1Ev
@@ -111,6 +164,13 @@
 // CHECK-NEXT: call void @objc_release(i8* [[T7]])
 // CHECK-NEXT: ret
 
+// Check that the Weak object passed to this constructor is not destructed after
+// the delegate constructor is called.
+
+// CHECK: define linkonce_odr void @_ZN7DerivedCI24BaseE4Weak(
+// CHECK: call void @_ZN4BaseC2E4Weak(
+// CHECK-NEXT: ret void
+
 // Implicitly-generated default constructor for ObjCMember
 // CHECK-LABEL: define linkonce_odr void @_ZN10ObjCMemberC2Ev
 // CHECK-NOT: objc_release
Index: test/CodeGenObjCXX/arc-forwarded-lambda-call.mm
===
--- test/CodeGenObjCXX/arc-forwarded-lambda-call.mm
+++ test/CodeGenObjCXX/arc-forwarded-lambda-call.mm
@@ -10,6 +10,17 @@
   // CHECK-NEXT: ret i8* [[T2]]
 }
 
+// Check that the delegating block invoke function doesn't destruct the Weak
+// object that is passed.
+
+// CHECK-LABEL: define internal void @___Z8testWeakv_block_invoke(
+// CHECK: call void @

[PATCH] D46135: [Driver, CodeGen] add options to enable/disable an FP cast optimization

2018-04-26 Thread Chandler Carruth via Phabricator via cfe-commits
chandlerc accepted this revision.
chandlerc added a comment.
This revision is now accepted and ready to land.

LGTM, thanks so much!


https://reviews.llvm.org/D46135



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


[PATCH] D34331: func.wrap.func.con: Unset function before destroying anything

2018-04-26 Thread Billy Robert O'Neal III via Phabricator via cfe-commits
BillyONeal added subscribers: STL_MSFT, BillyONeal.
BillyONeal added a comment.

@mclow.lists
@STL_MSFT

Why did tests for this this go into std? [reentrancy]/1 says this isn't 
required to work. Moreover, assignments in the dtor like this *can't* work in 
the general case because they would try to overwrite the SSO space. e.g. what 
do you expect this to do?

  std::function global;
  
  struct B {
  int data = 1729;
  void operator() {}
  };
  
  struct A {
  int data = 42;
  ~A() {
  global = std::function(B{}); // whoops, constructs a B on top 
of A if Small Functor Optimization engages
  assert(data == 42);
  }
  
  void operator() {}
  };
  
  int main() {
  global = std::function(A{});
  global = nullptr;
  }




Repository:
  rCXX libc++

https://reviews.llvm.org/D34331



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


  1   2   >