r305182 - Revert r305164/5/7.

2017-06-12 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Mon Jun 12 03:08:18 2017
New Revision: 305182

URL: http://llvm.org/viewvc/llvm-project?rev=305182&view=rev
Log:
Revert r305164/5/7.

cc1as does not currently access the "--" version of this flag. At the
very least this needs to be fixed and proper test cases need to be
added.

Simple reproducer:
clang -Wa,--compress-debug-sections /tmp/test.cc

Result:
error: unknown argument: '--compress-debug-sections'

Removed:
cfe/trunk/test/Driver/compress-noias.c
Modified:
cfe/trunk/include/clang/Driver/CC1Options.td
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/test/Driver/compress.c
cfe/trunk/test/Driver/nozlibcompress.c
cfe/trunk/tools/driver/cc1as_main.cpp

Modified: cfe/trunk/include/clang/Driver/CC1Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=305182&r1=305181&r2=305182&view=diff
==
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)
+++ cfe/trunk/include/clang/Driver/CC1Options.td Mon Jun 12 03:08:18 2017
@@ -134,6 +134,7 @@ def migrator_no_finalize_removal : Flag<
 
//===--===//
 
 let Flags = [CC1Option, CC1AsOption, NoDriverOption] in {
+
 def debug_info_kind_EQ : Joined<["-"], "debug-info-kind=">;
 def debug_info_macro : Flag<["-"], "debug-info-macro">,
   HelpText<"Emit macro debug information">;
@@ -143,16 +144,14 @@ def fdebug_compilation_dir : Separate<["
   HelpText<"The compilation directory to embed in the debug info.">;
 def dwarf_debug_flags : Separate<["-"], "dwarf-debug-flags">,
   HelpText<"The string to embed in the Dwarf debug flags record.">;
-def compress_debug_sections : Flag<["-"], "compress-debug-sections">,
-HelpText<"DWARF debug sections compression">;
-def compress_debug_sections_EQ : Flag<["-"], "compress-debug-sections=">,
-HelpText<"DWARF debug sections compression type">;
 def mno_exec_stack : Flag<["-"], "mnoexecstack">,
   HelpText<"Mark the file as not needing an executable stack">;
 def massembler_fatal_warnings : Flag<["-"], "massembler-fatal-warnings">,
   HelpText<"Make assembler warnings fatal">;
 def mrelax_relocations : Flag<["--"], "mrelax-relocations">,
 HelpText<"Use relaxable elf relocations">;
+def compress_debug_sections : Flag<["-"], "compress-debug-sections">,
+HelpText<"Compress DWARF debug sections using zlib">;
 def msave_temp_labels : Flag<["-"], "msave-temp-labels">,
   HelpText<"Save temporary labels in the symbol table. "
"Note this may change .s semantics and shouldn't generally be used "

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=305182&r1=305181&r2=305182&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Mon Jun 12 03:08:18 2017
@@ -1563,10 +1563,6 @@ def gdwarf_aranges : Flag<["-"], "gdwarf
 def gmodules : Flag <["-"], "gmodules">, Group,
   HelpText<"Generate debug info with external references to clang modules"
" or precompiled headers">;
-def gz : Flag<["-"], "gz">, Group,
-HelpText<"DWARF debug sections compression type">;
-def gz_EQ : Joined<["-"], "gz=">, Group,
-HelpText<"DWARF debug sections compression type">;
 def headerpad__max__install__names : Joined<["-"], 
"headerpad_max_install_names">;
 def help : Flag<["-", "--"], "help">, Flags<[CC1Option,CC1AsOption]>,
   HelpText<"Display available options">;

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=305182&r1=305181&r2=305182&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Mon Jun 12 03:08:18 2017
@@ -910,37 +910,6 @@ static void RenderDebugEnablingArgs(cons
   }
 }
 
-static void RenderDebugInfoCompressionArgs(const ArgList &Args,
-   ArgStringList &CmdArgs,
-   const Driver &D) {
-  const Arg *A = Args.getLastArg(options::OPT_gz, options::OPT_gz_EQ);
-  if (!A)
-return;
-
-  if (A->getOption().getID() == options::OPT_gz) {
-if (llvm::zlib::isAvailable())
-  CmdArgs.push_back("-compress-debug-sections");
-else
-  D.Diag(diag::warn_debug_compression_unavailable);
-return;
-  }
-
-  StringRef Value = A->getValue();
-  if (Value == "none") {
-CmdArgs.push_back("-compress-debug-sections=none");
-  } else if (Value == "zlib" || Value == "zlib-gnu") {
-if (llvm::zlib::isAvailabl

[PATCH] D33277: [Clang][x86][Inline Asm] - Enum support for MS syntax

2017-06-12 Thread Matan via Phabricator via cfe-commits
mharoush updated this revision to Diff 102172.
mharoush marked 6 inline comments as done.
mharoush added a comment.

Restored old test case for constant int folding and added check-label 
directives for each tester function.


Repository:
  rL LLVM

https://reviews.llvm.org/D33277

Files:
  lib/Sema/SemaStmtAsm.cpp
  test/CodeGen/x86-ms-inline-asm-enum_feature.cpp

Index: lib/Sema/SemaStmtAsm.cpp
===
--- lib/Sema/SemaStmtAsm.cpp
+++ lib/Sema/SemaStmtAsm.cpp
@@ -644,8 +644,8 @@
   // Referring to parameters is not allowed in naked functions.
   if (CheckNakedParmReference(Result.get(), *this))
 return ExprError();
-
-  QualType T = Result.get()->getType();
+  Expr *Res = Result.get();
+  QualType T = Res->getType();
 
   if (T->isDependentType()) {
 return Result;
@@ -657,16 +657,26 @@
   }
 
   // Otherwise, it needs to be a complete type.
-  if (RequireCompleteExprType(Result.get(), diag::err_asm_incomplete_type)) {
+  if (RequireCompleteExprType(Res, diag::err_asm_incomplete_type)) {
 return ExprError();
   }
 
   fillInlineAsmTypeInfo(Context, T, Info);
 
   // We can work with the expression as long as it's not an r-value.
-  if (!Result.get()->isRValue())
-Info.IsVarDecl = true;
+  if (!Res->isRValue()) {
+Info.setKindVariable();
+return Result;
+  }
 
+  Expr::EvalResult EvlResult;
+  // Try to evaluate the identifier as enum constant, currently we do not allow
+  // other constant integers to be folded.
+  if (isa(T) &&
+Res->EvaluateAsRValue(EvlResult, getASTContext())) {
+Info.ConstIntValue = EvlResult.Val.getInt();
+Info.setKindConstEnum();
+  }
   return Result;
 }
 
@@ -773,7 +783,7 @@
   fillInlineAsmTypeInfo(Context, Result.get()->getType(), Info);
 
   // Fields are "variables" as far as inline assembly is concerned.
-  Info.IsVarDecl = true;
+  Info.setKindVariable();
 
   return Result;
 }
Index: test/CodeGen/x86-ms-inline-asm-enum_feature.cpp
===
--- test/CodeGen/x86-ms-inline-asm-enum_feature.cpp
+++ test/CodeGen/x86-ms-inline-asm-enum_feature.cpp
@@ -0,0 +1,55 @@
+// REQUIRES: x86-registered-target
+// RUN: %clang_cc1 %s -fasm-blocks -emit-llvm -o - | FileCHECK %s
+namespace x {
+enum { A = 12 };
+struct y_t {
+	enum { A = 17 };
+	int r;
+} y;
+}
+// CHECK-LABEL: x86_enum_only
+void x86_enum_only(){
+  const int a = 0;
+  // CHECK-NOT: mov eax, [$$0]
+  // Other constant type folding is currently unwanted.
+  __asm mov eax, [a]
+  }
+
+// CHECK-LABEL: x86_enum_namespaces
+void x86_enum_namespaces() {
+  enum { A = 1 };
+  // CHECK: mov eax, $$12
+  __asm mov eax, x::A
+  // CHECK: mov eax, $$17
+  __asm mov eax, x::y_t::A
+  // CHECK: mov eax, $$1
+  __asm {mov eax, A}
+}
+
+// CHECK-LABEL: x86_enum_arithmethic
+void x86_enum_arithmethic() {
+  enum { A = 1, B };
+  // CHECK: mov eax, $$21
+  __asm mov eax, (A + 9) * 2 + A
+  // CHECK: mov eax, $$4
+  __asm mov eax, A << 2
+  // CHECK: mov eax, $$2
+  __asm mov eax, B & 3
+  // CHECK: mov eax, $$5
+  __asm mov eax, 3 + (B & 3)
+  // CHECK: mov eax, $$8
+  __asm mov eax, 2 << A * B
+}
+
+// CHECK-LABEL: x86_enum_mem
+void x86_enum_mem() {
+  int arr[4];
+  enum { A = 4, B };
+
+  // CHECK: mov eax, [($$12 + $$9) + $$4 * $$5 + $$3 + $$3 + eax]
+  __asm { mov eax, [(x::A + 9) + A * B + 3 + 3 + eax] }
+  // CHECK: mov eax, dword ptr $$4$0
+  __asm { mov eax, dword ptr [arr + A] }
+  // CHECK: mov eax, dword ptr $$8$0
+  __asm { mov eax, dword ptr A[arr + A] }
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D33278: [LLVM][x86][Inline Asm] - Enum support for MS syntax

2017-06-12 Thread Matan via Phabricator via cfe-commits
mharoush marked 3 inline comments as done.
mharoush added a comment.

ping


Repository:
  rL LLVM

https://reviews.llvm.org/D33278



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


[PATCH] D34102: [analyzer] Add portability package for the checkers.

2017-06-12 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ created this revision.

Checkers that find implementation-defined behavior seem to better be off by 
default - or, at least, there should be a way to turn them off - because we're 
not sure if our users are developing cross-platform code or target a specific 
platform. If the behavior is well-defined on any particular target platform, 
then the user may say "this code works correctly, the behavior is documented, i 
personally don't care about portability, so the analyzer shouldn't warn".

I'm introducing an `optin.portability` package with this patch. The UNIX 
zero-size-malloc check is moved here, because the behavior is 
implementation-defined according even to the C standard, and man pages of 
various platforms clearly document which behavior is implemented. Of course, 
that behavior is different on linux vs. bsd/mac though, which is the whole 
point of the checker.

Suggestions/complains are very welcome. I'm thinking of enabling portability 
checks by default when we're cross-compiling, or maybe on per-platform basis, 
eg. linux/bsd developers care about portability much more often (and in this 
case we shouldn't probably add the `optin` prefix to the package).


https://reviews.llvm.org/D34102

Files:
  include/clang/StaticAnalyzer/Checkers/Checkers.td
  lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
  test/Analysis/malloc-overflow2.c
  test/Analysis/unix-fns.c

Index: test/Analysis/unix-fns.c
===
--- test/Analysis/unix-fns.c
+++ test/Analysis/unix-fns.c
@@ -1,7 +1,7 @@
-// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core,unix.API,osx.API %s -analyzer-store=region -analyzer-output=plist -analyzer-eagerly-assume -analyzer-config faux-bodies=true -analyzer-config path-diagnostics-alternate=false -fblocks -verify -o %t.plist
+// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core,unix.API,osx.API,optin.portability.unix.API %s -analyzer-store=region -analyzer-output=plist -analyzer-eagerly-assume -analyzer-config faux-bodies=true -analyzer-config path-diagnostics-alternate=false -fblocks -verify -o %t.plist
 // RUN: FileCheck --input-file=%t.plist %s
 // RUN: mkdir -p %t.dir
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix.API,osx.API -analyzer-output=html -analyzer-config faux-bodies=true -fblocks -o %t.dir %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix.API,osx.API,optin.portability.unix.API -analyzer-output=html -analyzer-config faux-bodies=true -fblocks -o %t.dir %s
 // RUN: rm -fR %t.dir
 struct _opaque_pthread_once_t {
   long __sig;
Index: test/Analysis/malloc-overflow2.c
===
--- test/Analysis/malloc-overflow2.c
+++ test/Analysis/malloc-overflow2.c
@@ -1,4 +1,5 @@
 // RUN: %clang_analyze_cc1 -triple x86_64-unknown-unknown -analyzer-checker=alpha.security.MallocOverflow,unix -verify %s
+// RUN: %clang_analyze_cc1 -triple x86_64-unknown-unknown -analyzer-checker=alpha.security.MallocOverflow,unix,optin.portability.unix -DPORTABILITY -verify %s
 
 typedef __typeof__(sizeof(int)) size_t;
 extern void *malloc(size_t);
@@ -32,5 +33,8 @@
 }
 
 void *f(int n) {
-  return malloc(n * 0 * sizeof(int)); // expected-warning {{Call to 'malloc' has an allocation size of 0 bytes}}
+  return malloc(n * 0 * sizeof(int));
+#ifdef PORTABILITY
+  // expected-warning@-2{{Call to 'malloc' has an allocation size of 0 bytes}}
+#endif
 }
Index: lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
+++ lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
@@ -45,6 +45,8 @@
   mutable Optional Val_O_CREAT;
 
 public:
+  DefaultBool CheckMisuse, CheckPortability;
+
   void checkPreStmt(const CallExpr *CE, CheckerContext &C) const;
 
   void CheckOpen(CheckerContext &C, const CallExpr *CE) const;
@@ -437,29 +439,42 @@
   if (FName.empty())
 return;
 
-  SubChecker SC =
-llvm::StringSwitch(FName)
-  .Case("open", &UnixAPIChecker::CheckOpen)
-  .Case("openat", &UnixAPIChecker::CheckOpenAt)
-  .Case("pthread_once", &UnixAPIChecker::CheckPthreadOnce)
-  .Case("calloc", &UnixAPIChecker::CheckCallocZero)
-  .Case("malloc", &UnixAPIChecker::CheckMallocZero)
-  .Case("realloc", &UnixAPIChecker::CheckReallocZero)
-  .Case("reallocf", &UnixAPIChecker::CheckReallocfZero)
-  .Cases("alloca", "__builtin_alloca", &UnixAPIChecker::CheckAllocaZero)
-  .Case("__builtin_alloca_with_align",
-&UnixAPIChecker::CheckAllocaWithAlignZero)
-  .Case("valloc", &UnixAPIChecker::CheckVallocZero)
-  .Default(nullptr);
-
-  if (SC)
-(this->*SC)(C, CE);
+  if (CheckMisuse) {
+if (SubChecker SC =
+llvm::StringSwitch(FName)
+.Case("open", &UnixAPIChecker::CheckOpen)
+.Case("openat", &UnixAPIChecker::CheckOpenAt)
+.Case("pthread_

[PATCH] D34102: [analyzer] Add portability package for the checkers.

2017-06-12 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: include/clang/StaticAnalyzer/Checkers/Checkers.td:425
 
-def UnixAPIChecker : Checker<"API">,
+def UnixAPIMisuseChecker : Checker<"API">,
   HelpText<"Check calls to various UNIX/Posix functions">,

This rename is user-invisible and handy because it allows macros for 
`registerChecker` to work uniformly.


https://reviews.llvm.org/D34102



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


[PATCH] D33589: clang-format: consider not splitting tokens in optimization

2017-06-12 Thread Francois Ferrand via Phabricator via cfe-commits
Typz added a comment.

ping?


https://reviews.llvm.org/D33589



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


[PATCH] D33447: clang-format: add option to merge empty function body

2017-06-12 Thread Francois Ferrand via Phabricator via cfe-commits
Typz added a comment.

ping?


https://reviews.llvm.org/D33447



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


[PATCH] D32480: clang-format: Add CompactNamespaces option

2017-06-12 Thread Francois Ferrand via Phabricator via cfe-commits
Typz added a comment.

ping?


https://reviews.llvm.org/D32480



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


[PATCH] D34103: Allow use of fixed width integer types in builtin definitions

2017-06-12 Thread Edward Jones via Phabricator via cfe-commits
edward-jones created this revision.

This makes it possible to specify a bit width after the 'i' integer type 
specifier when defining builtins. The bswap and bitreverse builtins have been 
updated so that their definitions use fixed-width types instead of short, int 
and long, so that they work on targets where int != 32-bits and long != 64 bits.


https://reviews.llvm.org/D34103

Files:
  include/clang/Basic/Builtins.def
  lib/AST/ASTContext.cpp
  test/CodeGen/builtins.c

Index: test/CodeGen/builtins.c
===
--- test/CodeGen/builtins.c
+++ test/CodeGen/builtins.c
@@ -111,8 +111,9 @@
   P(object_size, (s0, 2));
   P(object_size, (s0, 3));
 
-  // Whatever
-
+  // CHECK: @llvm.bswap.i16
+  // CHECK: @llvm.bswap.i32
+  // CHECK: @llvm.bswap.i64
   P(bswap16, (N));
   P(bswap32, (N));
   P(bswap64, (N));
@@ -603,4 +604,4 @@
   __builtin_os_log_format(buf, "%s %% %s", data1, data2);
 }
 
-#endif
\ No newline at end of file
+#endif
Index: lib/AST/ASTContext.cpp
===
--- lib/AST/ASTContext.cpp
+++ lib/AST/ASTContext.cpp
@@ -8585,16 +8585,26 @@
 else
   Type = Context.ShortTy;
 break;
-  case 'i':
-if (HowLong == 3)
-  Type = Unsigned ? Context.UnsignedInt128Ty : Context.Int128Ty;
-else if (HowLong == 2)
-  Type = Unsigned ? Context.UnsignedLongLongTy : Context.LongLongTy;
-else if (HowLong == 1)
-  Type = Unsigned ? Context.UnsignedLongTy : Context.LongTy;
-else
-  Type = Unsigned ? Context.UnsignedIntTy : Context.IntTy;
+  case 'i': {
+char *End;
+unsigned BitWidth = strtoul(Str, &End, 10);
+if (End != Str) {
+  // Optional fixed width modifier
+  Str = End;
+  assert(HowLong == 0 && "Bad modifiers used with fixed-width integer");
+  Type = Context.getIntTypeForBitwidth(BitWidth, !Unsigned);
+} else {
+  if (HowLong == 3)
+Type = Unsigned ? Context.UnsignedInt128Ty : Context.Int128Ty;
+  else if (HowLong == 2)
+Type = Unsigned ? Context.UnsignedLongLongTy : Context.LongLongTy;
+  else if (HowLong == 1)
+Type = Unsigned ? Context.UnsignedLongTy : Context.LongTy;
+  else
+Type = Unsigned ? Context.UnsignedIntTy : Context.IntTy;
+}
 break;
+  }
   case 'c':
 assert(HowLong == 0 && "Bad modifiers used with 'c'!");
 if (Signed)
Index: include/clang/Basic/Builtins.def
===
--- include/clang/Basic/Builtins.def
+++ include/clang/Basic/Builtins.def
@@ -24,7 +24,7 @@
 //  b -> boolean
 //  c -> char
 //  s -> short
-//  i -> int
+//  i -> int, optionally followed by the bit width of the integer type
 //  h -> half
 //  f -> float
 //  d -> double
@@ -47,7 +47,9 @@
 //  p -> pid_t
 //  . -> "...".  This may only occur at the end of the function list.
 //
-// Types may be prefixed with the following modifiers:
+// Types may be prefixed with a number of modifiers. Modifiers which affect
+// the width of the integer type cannot be used if the integer is specified
+// as a fixed-width type.
 //  L   -> long (e.g. Li for 'long int')
 //  LL  -> long long
 //  LLL -> __int128_t (e.g. LLLi)
@@ -406,16 +408,14 @@
 BUILTIN(__builtin_popcountl , "iULi" , "nc")
 BUILTIN(__builtin_popcountll, "iULLi", "nc")
 
-// FIXME: These type signatures are not correct for targets with int != 32-bits
-// or with ULL != 64-bits.
-BUILTIN(__builtin_bswap16, "UsUs", "nc")
-BUILTIN(__builtin_bswap32, "UiUi", "nc")
-BUILTIN(__builtin_bswap64, "ULLiULLi", "nc")
+BUILTIN(__builtin_bswap16, "Ui16Ui16", "nc")
+BUILTIN(__builtin_bswap32, "Ui32Ui32", "nc")
+BUILTIN(__builtin_bswap64, "Ui64Ui64", "nc")
 
-BUILTIN(__builtin_bitreverse8, "UcUc", "nc")
-BUILTIN(__builtin_bitreverse16, "UsUs", "nc")
-BUILTIN(__builtin_bitreverse32, "UiUi", "nc")
-BUILTIN(__builtin_bitreverse64, "ULLiULLi", "nc")
+BUILTIN(__builtin_bitreverse8,  "Ui8Ui8", "nc")
+BUILTIN(__builtin_bitreverse16, "Ui16Ui16", "nc")
+BUILTIN(__builtin_bitreverse32, "Ui32Ui32", "nc")
+BUILTIN(__builtin_bitreverse64, "Ui64Ui64", "nc")
 
 // Random GCC builtins
 BUILTIN(__builtin_constant_p, "i.", "nctu")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D30946: [ScopePrinting] Added support to print full scopes of types and declarations.

2017-06-12 Thread Simon Schroeder via Phabricator via cfe-commits
schroedersi added a comment.

Ping :)


https://reviews.llvm.org/D30946



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


[PATCH] D33823: [clang-format] Support sorting using declarations

2017-06-12 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added a comment.

@klimek: ping


https://reviews.llvm.org/D33823



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


[libcxx] r305191 - [array.tuple]/1 says that instantiating tuple_element> is ill-formed if N >= M. We didn't do that. Add a static_assert to cause a failure, and a test that checks that

2017-06-12 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Mon Jun 12 09:41:37 2017
New Revision: 305191

URL: http://llvm.org/viewvc/llvm-project?rev=305191&view=rev
Log:
[array.tuple]/1 says that instantiating tuple_element> is 
ill-formed if N >= M.  We didn't do that. Add a static_assert to cause a 
failure, and a test that checks that we failed

Added:

libcxx/trunk/test/std/containers/sequences/array/array.tuple/tuple_element.fail.cpp
Modified:
libcxx/trunk/include/array

Modified: libcxx/trunk/include/array
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/array?rev=305191&r1=305190&r2=305191&view=diff
==
--- libcxx/trunk/include/array (original)
+++ libcxx/trunk/include/array Mon Jun 12 09:41:37 2017
@@ -296,6 +296,7 @@ class _LIBCPP_TEMPLATE_VIS tuple_size
 class _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, array<_Tp, _Size> >
 {
+static_assert(_Ip < _Size, "Index out of bounds in std::tuple_element<> 
(std::array)");
 public:
 typedef _Tp type;
 };

Added: 
libcxx/trunk/test/std/containers/sequences/array/array.tuple/tuple_element.fail.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/sequences/array/array.tuple/tuple_element.fail.cpp?rev=305191&view=auto
==
--- 
libcxx/trunk/test/std/containers/sequences/array/array.tuple/tuple_element.fail.cpp
 (added)
+++ 
libcxx/trunk/test/std/containers/sequences/array/array.tuple/tuple_element.fail.cpp
 Mon Jun 12 09:41:37 2017
@@ -0,0 +1,35 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// 
+
+// tuple_element >::type
+
+// Prevent -Warray-bounds from issuing a diagnostic when testing with clang 
verify.
+#if defined(__clang__)
+#pragma clang diagnostic ignored "-Warray-bounds"
+#endif
+
+#include 
+#include 
+
+
+// std::array is explicitly allowed to be initialized with A a = { init-list 
};.
+// Disable the missing braces warning for this reason.
+#include "disable_missing_braces_warning.h"
+
+int main()
+{
+{
+typedef double T;
+typedef std::array C;
+std::tuple_element<3, C> foo; // expected-note {{requested here}}
+// expected-error@array:* {{static_assert failed "Index out of bounds 
in std::tuple_element<> (std::array)"}}
+}
+}


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


[PATCH] D33447: clang-format: add option to merge empty function body

2017-06-12 Thread Daniel Jasper via Phabricator via cfe-commits
djasper accepted this revision.
djasper added a comment.
This revision is now accepted and ready to land.

Looks good.


https://reviews.llvm.org/D33447



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


[PATCH] D32480: clang-format: Add CompactNamespaces option

2017-06-12 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added a comment.

In https://reviews.llvm.org/D32480#773807, @Typz wrote:

> So how do I proceed?
>
> 1. Keep the CompactNamespace option, and make "compacted" namespaces always 
> add at most one level of indentation
> 2. Or assume that this can only ever usefully work with the behavior of 
> NI_None and add an additional enum value NI_Compact.


I'd vote for (1).

> And should we limit 'compacting' to namespace which start and end at 
> consecutive lines [e.g. exactly the same conditions as C++17 nested 
> namespaces], or is the current implementation enough [merge all adjacent 
> beginning and all adjacent endings] ?

I'd vote for the former.


https://reviews.llvm.org/D32480



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


Re: [PATCH] D33932: [clang-format] Add support for case-insensitive header matching and use it to improve support for LLVM-style include sorting.

2017-06-12 Thread David Blaikie via cfe-commits
On Tue, Jun 6, 2017 at 3:56 AM Chandler Carruth via Phabricator via
cfe-commits  wrote:

> chandlerc created this revision.
> Herald added subscribers: mcrosier, sanjoy, klimek.
>
> This really is a collection of improvements to the rules for LLVM
> include sorting:
>
> - We have gmock headers now, so it adds support for those to one of the
> categories.
> - LLVM does use 'FooTest.cpp' files to test 'Foo.h' so it adds that suffix
> for finding a main header.
> - At times the test file's case may not match the header file's case, so
> adds support for case-insensitive regex matching of these things.
>

Curious - where does this last one come up? Can we fix those, or do they
look good/intentional/worth keeping?


>
> With this set of changes, I can't spot any misbehaviors when re-sorting
> all of LLVM's unittest '#include' lines.
>
> Note that I don't know the first thing about testing clang-format, so
> please
> feel free to tell me what all I need to be doing here.
>
>
> https://reviews.llvm.org/D33932
>
> Files:
>   include/clang/Format/Format.h
>   lib/Format/Format.cpp
>   unittests/Format/SortIncludesTest.cpp
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34102: [analyzer] Add portability package for the checkers.

2017-06-12 Thread Anna Zaks via Phabricator via cfe-commits
zaks.anna added inline comments.



Comment at: include/clang/StaticAnalyzer/Checkers/Checkers.td:454
+def UnixAPIPortabilityChecker : Checker<"API">,
+  HelpText<"Finds implementation-defined behavior in UNIX/Posix functions">,
+  DescFile<"UnixAPIChecker.cpp">;

Does this need to be in unix?


https://reviews.llvm.org/D34102



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


Re: r304892 - [Sema] Silence unused variable warning.

2017-06-12 Thread David Blaikie via cfe-commits
Richard, looks like this might be better as:

if (auto QL = OE->getQualifierLoc())
  ... QL.getBeginLoc() ...

?


On Wed, Jun 7, 2017 at 3:23 AM Benjamin Kramer via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: d0k
> Date: Wed Jun  7 05:23:17 2017
> New Revision: 304892
>
> URL: http://llvm.org/viewvc/llvm-project?rev=304892&view=rev
> Log:
> [Sema] Silence unused variable warning.
>
> Modified:
> cfe/trunk/lib/Sema/SemaExpr.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=304892&r1=304891&r2=304892&view=diff
>
> ==
> --- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Jun  7 05:23:17 2017
> @@ -11843,7 +11843,7 @@ ExprResult Sema::BuildBinOp(Scope *S, So
>std::any_of(OE->decls_begin(), OE->decls_end(), [](NamedDecl
> *ND) {
>  return isa(ND);
>})) {
> -if (auto *Q = OE->getQualifier()) {
> +if (OE->getQualifier()) {
>Diag(OE->getQualifierLoc().getBeginLoc(),
> diag::err_template_kw_missing)
>  << OE->getName().getAsString() << "";
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D33910: [ubsan] Detect invalid unsigned pointer index expression (clang)

2017-06-12 Thread Will Dietz via Phabricator via cfe-commits
dtzWill accepted this revision.
dtzWill added a comment.

LGTM!

Sorry for missing this originally, as a perhaps interesting note:
the checks were extracted from a research prototype that worked at the IR level 
--where pointer itself is unsigned but the offsets (including the computed 
total offset) is a signed expression[1].
(we also tracked conversions and whatnot, so... well things were different.  
Anyway, sorry for missing this!)

This looks great to me, thanks for identifying this and putting it together!

[1] 
http://llvm.org/docs/GetElementPtr.html#what-happens-if-a-gep-computation-overflows


https://reviews.llvm.org/D33910



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


[PATCH] D34105: Define _GNU_SOURCE for rtems c++

2017-06-12 Thread Walter Lee via Phabricator via cfe-commits
waltl created this revision.

This is required by the libc++ locale support.


https://reviews.llvm.org/D34105

Files:
  lib/Basic/Targets.cpp
  test/Preprocessor/init.c


Index: test/Preprocessor/init.c
===
--- test/Preprocessor/init.c
+++ test/Preprocessor/init.c
@@ -8779,6 +8779,7 @@
 // KFREEBSDI686-DEFINE:#define __GLIBC__ 1
 //
 // RUN: %clang_cc1 -x c++ -triple i686-pc-linux-gnu -fobjc-runtime=gcc -E -dM 
< /dev/null | FileCheck -match-full-lines -check-prefix GNUSOURCE %s
+// RUN: %clang_cc1 -x c++ -triple sparc-rtems-elf -E -dM < /dev/null | 
FileCheck -match-full-lines -check-prefix GNUSOURCE %s
 // GNUSOURCE:#define _GNU_SOURCE 1
 //
 // RUN: %clang_cc1 -x c++ -std=c++98 -fno-rtti -E -dM < /dev/null | FileCheck 
-match-full-lines -check-prefix NORTTI %s
Index: lib/Basic/Targets.cpp
===
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -4734,6 +4734,9 @@
 
 Builder.defineMacro("__rtems__");
 Builder.defineMacro("__ELF__");
+// Required by the libc++ locale support.
+if (Opts.CPlusPlus)
+  Builder.defineMacro("_GNU_SOURCE");
   }
 
 public:


Index: test/Preprocessor/init.c
===
--- test/Preprocessor/init.c
+++ test/Preprocessor/init.c
@@ -8779,6 +8779,7 @@
 // KFREEBSDI686-DEFINE:#define __GLIBC__ 1
 //
 // RUN: %clang_cc1 -x c++ -triple i686-pc-linux-gnu -fobjc-runtime=gcc -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix GNUSOURCE %s
+// RUN: %clang_cc1 -x c++ -triple sparc-rtems-elf -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix GNUSOURCE %s
 // GNUSOURCE:#define _GNU_SOURCE 1
 //
 // RUN: %clang_cc1 -x c++ -std=c++98 -fno-rtti -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix NORTTI %s
Index: lib/Basic/Targets.cpp
===
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -4734,6 +4734,9 @@
 
 Builder.defineMacro("__rtems__");
 Builder.defineMacro("__ELF__");
+// Required by the libc++ locale support.
+if (Opts.CPlusPlus)
+  Builder.defineMacro("_GNU_SOURCE");
   }
 
 public:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34106: [clangd] Use 'std::string' for VFSTag instead of 'int'

2017-06-12 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov created this revision.

https://reviews.llvm.org/D34106

Files:
  clangd/ClangdServer.h
  unittests/clangd/ClangdTests.cpp


Index: unittests/clangd/ClangdTests.cpp
===
--- unittests/clangd/ClangdTests.cpp
+++ unittests/clangd/ClangdTests.cpp
@@ -386,13 +386,13 @@
   auto FooCpp = getVirtualTestFilePath("foo.cpp");
   const auto SourceContents = "int a;";
   FS->Files[FooCpp] = SourceContents;
-  FS->Tag = 123;
+  FS->Tag = "123";
 
   Server.addDocument(FooCpp, SourceContents);
   EXPECT_EQ(DiagConsumer->lastVFSTag(), FS->Tag);
   EXPECT_EQ(Server.codeComplete(FooCpp, Position{0, 0}).Tag, FS->Tag);
 
-  FS->Tag = 321;
+  FS->Tag = "321";
   Server.addDocument(FooCpp, SourceContents);
   EXPECT_EQ(DiagConsumer->lastVFSTag(), FS->Tag);
   EXPECT_EQ(Server.codeComplete(FooCpp, Position{0, 0}).Tag, FS->Tag);
Index: clangd/ClangdServer.h
===
--- clangd/ClangdServer.h
+++ clangd/ClangdServer.h
@@ -43,20 +43,22 @@
 Position offsetToPosition(StringRef Code, size_t Offset);
 
 /// A tag supplied by the FileSytemProvider.
-typedef int VFSTag;
+typedef std::string VFSTag;
 
 /// A value of an arbitrary type and VFSTag that was supplied by the
 /// FileSystemProvider when this value was computed.
 template  class Tagged {
 public:
   template 
-  Tagged(U &&Value, VFSTag Tag) : Value(std::forward(Value)), Tag(Tag) {}
+  Tagged(U &&Value, VFSTag Tag)
+  : Value(std::forward(Value)), Tag(std::move(Tag)) {}
 
   template 
   Tagged(const Tagged &Other) : Value(Other.Value), Tag(Other.Tag) {}
 
   template 
-  Tagged(Tagged &&Other) : Value(std::move(Other.Value)), Tag(Other.Tag) {}
+  Tagged(Tagged &&Other)
+  : Value(std::move(Other.Value)), Tag(std::move(Other.Tag)) {}
 
   T Value;
   VFSTag Tag;


Index: unittests/clangd/ClangdTests.cpp
===
--- unittests/clangd/ClangdTests.cpp
+++ unittests/clangd/ClangdTests.cpp
@@ -386,13 +386,13 @@
   auto FooCpp = getVirtualTestFilePath("foo.cpp");
   const auto SourceContents = "int a;";
   FS->Files[FooCpp] = SourceContents;
-  FS->Tag = 123;
+  FS->Tag = "123";
 
   Server.addDocument(FooCpp, SourceContents);
   EXPECT_EQ(DiagConsumer->lastVFSTag(), FS->Tag);
   EXPECT_EQ(Server.codeComplete(FooCpp, Position{0, 0}).Tag, FS->Tag);
 
-  FS->Tag = 321;
+  FS->Tag = "321";
   Server.addDocument(FooCpp, SourceContents);
   EXPECT_EQ(DiagConsumer->lastVFSTag(), FS->Tag);
   EXPECT_EQ(Server.codeComplete(FooCpp, Position{0, 0}).Tag, FS->Tag);
Index: clangd/ClangdServer.h
===
--- clangd/ClangdServer.h
+++ clangd/ClangdServer.h
@@ -43,20 +43,22 @@
 Position offsetToPosition(StringRef Code, size_t Offset);
 
 /// A tag supplied by the FileSytemProvider.
-typedef int VFSTag;
+typedef std::string VFSTag;
 
 /// A value of an arbitrary type and VFSTag that was supplied by the
 /// FileSystemProvider when this value was computed.
 template  class Tagged {
 public:
   template 
-  Tagged(U &&Value, VFSTag Tag) : Value(std::forward(Value)), Tag(Tag) {}
+  Tagged(U &&Value, VFSTag Tag)
+  : Value(std::forward(Value)), Tag(std::move(Tag)) {}
 
   template 
   Tagged(const Tagged &Other) : Value(Other.Value), Tag(Other.Tag) {}
 
   template 
-  Tagged(Tagged &&Other) : Value(std::move(Other.Value)), Tag(Other.Tag) {}
+  Tagged(Tagged &&Other)
+  : Value(std::move(Other.Value)), Tag(std::move(Other.Tag)) {}
 
   T Value;
   VFSTag Tag;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34107: [clangd] Allow to override contents of the file during completion.

2017-06-12 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov created this revision.

https://reviews.llvm.org/D34107

Files:
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  unittests/clangd/ClangdTests.cpp

Index: unittests/clangd/ClangdTests.cpp
===
--- unittests/clangd/ClangdTests.cpp
+++ unittests/clangd/ClangdTests.cpp
@@ -398,5 +398,69 @@
   EXPECT_EQ(Server.codeComplete(FooCpp, Position{0, 0}).Tag, FS->Tag);
 }
 
+class ClangdCompletionTest : public ClangdVFSTest {
+ protected:
+  bool ContainsItem(std::vector const& Items, StringRef Name) {
+for (const auto &Item : Items) {
+  if (Item.insertText == Name)
+return true;
+}
+return false;
+  }
+};
+
+TEST_F(ClangdCompletionTest, CheckContentsOverride) {
+  MockFSProvider *FS;
+
+  ClangdServer Server(llvm::make_unique(),
+  llvm::make_unique(),
+  getAndMove(llvm::make_unique(), FS),
+  /*RunSynchronously=*/false);
+
+  auto FooCpp = getVirtualTestFilePath("foo.cpp");
+  const auto SourceContents = R"cpp(
+int aba;
+int b =   ;
+)cpp";
+
+  const auto OverridenSourceContents = R"cpp(
+int cbc;
+int b =   ;
+)cpp";
+  // Complete after '=' sign. We need to be careful to keep the SourceContents'
+  // size the same.
+  // We complete on the 3rd line(2nd in zero-based numbering), because raw
+  // string literal of the SourceContents starts with a newline(it's easy to
+  // miss).
+  Position CompletePos = {2, 8};
+  FS->Files[FooCpp] = SourceContents;
+
+  Server.addDocument(FooCpp, SourceContents);
+
+  {
+auto CodeCompletionResults1 =
+Server.codeComplete(FooCpp, CompletePos, None).Value;
+EXPECT_TRUE(ContainsItem(CodeCompletionResults1, "aba"));
+EXPECT_FALSE(ContainsItem(CodeCompletionResults1, "cbc"));
+  }
+
+  {
+auto CodeCompletionResultsOverriden =
+Server
+.codeComplete(FooCpp, CompletePos,
+  StringRef(OverridenSourceContents))
+.Value;
+EXPECT_TRUE(ContainsItem(CodeCompletionResultsOverriden, "cbc"));
+EXPECT_FALSE(ContainsItem(CodeCompletionResultsOverriden, "aba"));
+  }
+
+  {
+auto CodeCompletionResults2 =
+Server.codeComplete(FooCpp, CompletePos, None).Value;
+EXPECT_TRUE(ContainsItem(CodeCompletionResults2, "aba"));
+EXPECT_FALSE(ContainsItem(CodeCompletionResults2, "cbc"));
+  }
+}
+
 } // namespace clangd
 } // namespace clang
Index: clangd/ClangdServer.h
===
--- clangd/ClangdServer.h
+++ clangd/ClangdServer.h
@@ -150,8 +150,15 @@
   /// Force \p File to be reparsed using the latest contents.
   void forceReparse(PathRef File);
 
-  /// Run code completion for \p File at \p Pos.
-  Tagged> codeComplete(PathRef File, Position Pos);
+  /// Run code completion for \p File at \p Pos. If \p OverridenContents is not
+  /// None, they will used only for code completion, i.e. no diagnostics update
+  /// will be scheduled and a draft for \p File will not be updated.
+  /// If \p OverridenContents is None, contents of the current draft for \p File
+  /// will be used.
+  /// This method should only be called for currently tracked files.
+  Tagged>
+  codeComplete(PathRef File, Position Pos,
+   llvm::Optional OverridenContents = llvm::None);
 
   /// Run formatting for \p Rng inside \p File.
   std::vector formatRange(PathRef File, Range Rng);
Index: clangd/ClangdServer.cpp
===
--- clangd/ClangdServer.cpp
+++ clangd/ClangdServer.cpp
@@ -184,17 +184,27 @@
   addDocument(File, getDocument(File));
 }
 
-Tagged> ClangdServer::codeComplete(PathRef File,
-   Position Pos) {
-  auto FileContents = DraftMgr.getDraft(File);
-  assert(FileContents.Draft && "codeComplete is called for non-added document");
+Tagged>
+ClangdServer::codeComplete(PathRef File, Position Pos,
+   llvm::Optional OverridenContents) {
+  if (!OverridenContents) {
+auto FileContents = DraftMgr.getDraft(File);
+assert(FileContents.Draft &&
+   "codeComplete is called for non-added document");
+
+OverridenContents = *FileContents.Draft;
+  }
 
   std::vector Result;
   auto TaggedFS = FSProvider->getTaggedFileSystem();
-  Units.runOnUnitWithoutReparse(
-  File, *FileContents.Draft, *CDB, PCHs, TaggedFS.Value, [&](ClangdUnit &Unit) {
-Result = Unit.codeComplete(*FileContents.Draft, Pos, TaggedFS.Value);
-  });
+  // It would be nice to use runOnUnitWithoutReparse here, but we can't
+  // guarantee the correctness of code completion cache here if we don't do the
+  // reparse.
+  Units.runOnUnit(File, *OverridenContents, *CDB, PCHs, TaggedFS.Value,
+  [&](ClangdUnit &Unit) {
+Result = Unit.codeComplete(*OverridenContents, Pos,
+   TaggedFS.V

r305195 - [Sema][C++1z] Ensure binding in dependent range for have non-null type

2017-06-12 Thread Erik Pilkington via cfe-commits
Author: epilk
Date: Mon Jun 12 11:11:06 2017
New Revision: 305195

URL: http://llvm.org/viewvc/llvm-project?rev=305195&view=rev
Log:
[Sema][C++1z] Ensure binding in dependent range for have non-null type

Fixes PR32172

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

Modified:
cfe/trunk/lib/Sema/SemaStmt.cpp
cfe/trunk/test/SemaCXX/cxx1z-decomposition.cpp

Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=305195&r1=305194&r2=305195&view=diff
==
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Mon Jun 12 11:11:06 2017
@@ -2206,8 +2206,12 @@ Sema::BuildCXXForRangeStmt(SourceLocatio
 
 // Deduce any 'auto's in the loop variable as 'DependentTy'. We'll fill
 // them in properly when we instantiate the loop.
-if (!LoopVar->isInvalidDecl() && Kind != BFRK_Check)
+if (!LoopVar->isInvalidDecl() && Kind != BFRK_Check) {
+  if (auto *DD = dyn_cast(LoopVar))
+for (auto *Binding : DD->bindings())
+  Binding->setType(Context.DependentTy);
   LoopVar->setType(SubstAutoType(LoopVar->getType(), Context.DependentTy));
+}
   } else if (!BeginDeclStmt.get()) {
 SourceLocation RangeLoc = RangeVar->getLocation();
 

Modified: cfe/trunk/test/SemaCXX/cxx1z-decomposition.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx1z-decomposition.cpp?rev=305195&r1=305194&r2=305195&view=diff
==
--- cfe/trunk/test/SemaCXX/cxx1z-decomposition.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx1z-decomposition.cpp Mon Jun 12 11:11:06 2017
@@ -70,4 +70,10 @@ int error_recovery() {
   return foobar_; // expected-error {{undeclared identifier 'foobar_'}}
 }
 
+// PR32172
+template  void dependent_foreach(T t) {
+  for (auto [a,b,c] : t)
+a,b,c;
+}
+
 // FIXME: by-value array copies


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


[PATCH] D34096: [Sema][C++1z] Ensure structured binding's bindings in dependent foreach have non-null type

2017-06-12 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL305195: [Sema][C++1z] Ensure binding in dependent range for 
have non-null type (authored by epilk).

Changed prior to commit:
  https://reviews.llvm.org/D34096?vs=102149&id=102191#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34096

Files:
  cfe/trunk/lib/Sema/SemaStmt.cpp
  cfe/trunk/test/SemaCXX/cxx1z-decomposition.cpp


Index: cfe/trunk/lib/Sema/SemaStmt.cpp
===
--- cfe/trunk/lib/Sema/SemaStmt.cpp
+++ cfe/trunk/lib/Sema/SemaStmt.cpp
@@ -2206,8 +2206,12 @@
 
 // Deduce any 'auto's in the loop variable as 'DependentTy'. We'll fill
 // them in properly when we instantiate the loop.
-if (!LoopVar->isInvalidDecl() && Kind != BFRK_Check)
+if (!LoopVar->isInvalidDecl() && Kind != BFRK_Check) {
+  if (auto *DD = dyn_cast(LoopVar))
+for (auto *Binding : DD->bindings())
+  Binding->setType(Context.DependentTy);
   LoopVar->setType(SubstAutoType(LoopVar->getType(), Context.DependentTy));
+}
   } else if (!BeginDeclStmt.get()) {
 SourceLocation RangeLoc = RangeVar->getLocation();
 
Index: cfe/trunk/test/SemaCXX/cxx1z-decomposition.cpp
===
--- cfe/trunk/test/SemaCXX/cxx1z-decomposition.cpp
+++ cfe/trunk/test/SemaCXX/cxx1z-decomposition.cpp
@@ -70,4 +70,10 @@
   return foobar_; // expected-error {{undeclared identifier 'foobar_'}}
 }
 
+// PR32172
+template  void dependent_foreach(T t) {
+  for (auto [a,b,c] : t)
+a,b,c;
+}
+
 // FIXME: by-value array copies


Index: cfe/trunk/lib/Sema/SemaStmt.cpp
===
--- cfe/trunk/lib/Sema/SemaStmt.cpp
+++ cfe/trunk/lib/Sema/SemaStmt.cpp
@@ -2206,8 +2206,12 @@
 
 // Deduce any 'auto's in the loop variable as 'DependentTy'. We'll fill
 // them in properly when we instantiate the loop.
-if (!LoopVar->isInvalidDecl() && Kind != BFRK_Check)
+if (!LoopVar->isInvalidDecl() && Kind != BFRK_Check) {
+  if (auto *DD = dyn_cast(LoopVar))
+for (auto *Binding : DD->bindings())
+  Binding->setType(Context.DependentTy);
   LoopVar->setType(SubstAutoType(LoopVar->getType(), Context.DependentTy));
+}
   } else if (!BeginDeclStmt.get()) {
 SourceLocation RangeLoc = RangeVar->getLocation();
 
Index: cfe/trunk/test/SemaCXX/cxx1z-decomposition.cpp
===
--- cfe/trunk/test/SemaCXX/cxx1z-decomposition.cpp
+++ cfe/trunk/test/SemaCXX/cxx1z-decomposition.cpp
@@ -70,4 +70,10 @@
   return foobar_; // expected-error {{undeclared identifier 'foobar_'}}
 }
 
+// PR32172
+template  void dependent_foreach(T t) {
+  for (auto [a,b,c] : t)
+a,b,c;
+}
+
 // FIXME: by-value array copies
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34102: [analyzer] Add portability package for the checkers.

2017-06-12 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: include/clang/StaticAnalyzer/Checkers/Checkers.td:454
+def UnixAPIPortabilityChecker : Checker<"API">,
+  HelpText<"Finds implementation-defined behavior in UNIX/Posix functions">,
+  DescFile<"UnixAPIChecker.cpp">;

zaks.anna wrote:
> Does this need to be in unix?
Well,
  1. the description still says "UNIX/Posix" and
  2. even if we believe that `malloc` isn't a UNIX/Posix-specific thing, we'd 
also need to move our `MallocChecker` out of the `unix` package.

This is probably the right thing to do, but i didn't try to do it here. If we 
want this, i'd move the portability checker out of `unix` now and deal with 
`MallocChecker` in another patch. I can also move the portability checker's 
code into `MallocChecker.cpp`, because that's what we always wanted to do, 
according to a `UnixAPIChecker`'s FIXME.


https://reviews.llvm.org/D34102



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


[PATCH] D33904: Add a __has_attribute_enhancement macro to clang

2017-06-12 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added inline comments.



Comment at: docs/LanguageExtensions.rst:176
+For example, clang's ``overloadable`` attribute has existed since before Clang
+3.5, but in Clang 5.0 it gained was modified to support so-called "unmarked
+overloads".  One can use ``__has_attribute_enhancement`` to query whether clang

Do you need "gained" here?


https://reviews.llvm.org/D33904



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


[libcxx] r305196 - Make tuple_element static_assert in pair if the index is out of range. Also, add a message to variant_alternative<> in the similar case (it already asserted). Add tests for this

2017-06-12 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Mon Jun 12 11:13:17 2017
New Revision: 305196

URL: http://llvm.org/viewvc/llvm-project?rev=305196&view=rev
Log:
Make tuple_element static_assert in pair if the index is out of range. Also, 
add a message to variant_alternative<> in the similar case (it already 
asserted). Add tests for this

Added:

libcxx/trunk/test/libcxx/utilities/utility/pairs/pairs.pair/pair.tuple_element.fail.cpp
libcxx/trunk/test/libcxx/utilities/variant/variant.variant/variant.helper/

libcxx/trunk/test/libcxx/utilities/variant/variant.variant/variant.helper/variant_alternative.fail.cpp
Modified:
libcxx/trunk/include/utility
libcxx/trunk/include/variant

Modified: libcxx/trunk/include/utility
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/utility?rev=305196&r1=305195&r2=305196&view=diff
==
--- libcxx/trunk/include/utility (original)
+++ libcxx/trunk/include/utility Mon Jun 12 11:13:17 2017
@@ -653,6 +653,12 @@ template 
   class _LIBCPP_TEMPLATE_VIS tuple_size >
 : public integral_constant {};
 
+template 
+class _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, pair<_T1, _T2> >
+{
+static_assert(_Ip < 2, "Index out of bounds in 
std::tuple_element>");
+};
+
 template 
 class _LIBCPP_TEMPLATE_VIS tuple_element<0, pair<_T1, _T2> >
 {

Modified: libcxx/trunk/include/variant
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/variant?rev=305196&r1=305195&r2=305196&view=diff
==
--- libcxx/trunk/include/variant (original)
+++ libcxx/trunk/include/variant Mon Jun 12 11:13:17 2017
@@ -278,7 +278,7 @@ struct _LIBCPP_TEMPLATE_VIS variant_alte
 
 template 
 struct _LIBCPP_TEMPLATE_VIS variant_alternative<_Ip, variant<_Types...>> {
-  static_assert(_Ip < sizeof...(_Types));
+  static_assert(_Ip < sizeof...(_Types), "Index out of bounds in 
std::variant_alternative<>");
   using type = __type_pack_element<_Ip, _Types...>;
 };
 

Added: 
libcxx/trunk/test/libcxx/utilities/utility/pairs/pairs.pair/pair.tuple_element.fail.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/utilities/utility/pairs/pairs.pair/pair.tuple_element.fail.cpp?rev=305196&view=auto
==
--- 
libcxx/trunk/test/libcxx/utilities/utility/pairs/pairs.pair/pair.tuple_element.fail.cpp
 (added)
+++ 
libcxx/trunk/test/libcxx/utilities/utility/pairs/pairs.pair/pair.tuple_element.fail.cpp
 Mon Jun 12 11:13:17 2017
@@ -0,0 +1,25 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// 
+
+// template  struct pair
+
+// tuple_element >::type
+
+#include 
+
+int main()
+{
+{
+typedef std::pair P;
+std::tuple_element<2, P>::type foo; // expected-note {{requested here}}
+// expected-error@utility:* {{static_assert failed "Index out of 
bounds in std::tuple_element>"}}
+}
+}

Added: 
libcxx/trunk/test/libcxx/utilities/variant/variant.variant/variant.helper/variant_alternative.fail.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/utilities/variant/variant.variant/variant.helper/variant_alternative.fail.cpp?rev=305196&view=auto
==
--- 
libcxx/trunk/test/libcxx/utilities/variant/variant.variant/variant.helper/variant_alternative.fail.cpp
 (added)
+++ 
libcxx/trunk/test/libcxx/utilities/variant/variant.variant/variant.helper/variant_alternative.fail.cpp
 Mon Jun 12 11:13:17 2017
@@ -0,0 +1,34 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// 
+
+// template  struct variant_alternative; // undefined
+// template  struct variant_alternative;
+// template  struct variant_alternative;
+// template  struct variant_alternative;
+// template 
+//   using variant_alternative_t = typename variant_alternative::type;
+//
+// template 
+//struct variant_alternative>;
+
+
+#include 
+#include 
+
+
+int main()
+{
+{
+typedef std::variant T;
+std::variant_alternative<2, T>::type foo; // expected-note {{requested 
here}}
+// expected-error@variant:* {{static_assert failed "Index out of 
bounds in std::variant_alternative<>"}}
+}
+}


___
cfe-commits mailing list
cfe-commits@li

[PATCH] D33904: Add a __has_attribute_enhancement macro to clang

2017-06-12 Thread Hal Finkel via Phabricator via cfe-commits
hfinkel added a comment.

I prefer `__has_attribute_feature` to enhancement. I don't see why we need a 
new macro for this, however. Why not just use 
`__has_feature(overloadable_unmarked)` or similar?


https://reviews.llvm.org/D33904



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


Re: [libcxxabi] r305173 - cxa_demangle: fix -Wimplicit-fallthrough for GCC:7

2017-06-12 Thread Erik Pilkington via cfe-commits

Clang warns on macos here:
/Users/epilk/llvm/projects/libcxxabi/src/cxa_demangle.cpp:2261:27: 
warning: unknown attribute 'fallthrough' ignored [-Wunknown-attributes]

[[gnu::fallthrough]];
  ^
Can you try defining a compatibility macro like LLVM_FALLTHROUGH for this?

On 6/11/17 3:57 PM, Saleem Abdulrasool via cfe-commits wrote:

Author: compnerd
Date: Sun Jun 11 17:57:31 2017
New Revision: 305173

URL: http://llvm.org/viewvc/llvm-project?rev=305173&view=rev
Log:
cxa_demangle: fix -Wimplicit-fallthrough for GCC:7

Use the C++11 (formalised in C++17) tag to indicate a fallthrough in the
switch case.  Silences a -Wimplicit-fallthrough warning with gcc:7

Modified:
 libcxxabi/trunk/src/cxa_demangle.cpp

Modified: libcxxabi/trunk/src/cxa_demangle.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_demangle.cpp?rev=305173&r1=305172&r2=305173&view=diff
==
--- libcxxabi/trunk/src/cxa_demangle.cpp (original)
+++ libcxxabi/trunk/src/cxa_demangle.cpp Sun Jun 11 17:57:31 2017
@@ -2258,7 +2258,7 @@ parse_type(const char* first, const char
  break;
  }
  }
-// drop through
+[[gnu::fallthrough]];
  default:
  // must check for builtin-types before 
class-enum-types to avoid
  // ambiguities with operator-names


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


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


[libcxx] r305198 - Mark the recent variant test as UNSUPPORTED for C++ before 17

2017-06-12 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Mon Jun 12 11:33:41 2017
New Revision: 305198

URL: http://llvm.org/viewvc/llvm-project?rev=305198&view=rev
Log:
Mark the recent variant test as UNSUPPORTED for C++ before 17

Modified:

libcxx/trunk/test/libcxx/utilities/variant/variant.variant/variant.helper/variant_alternative.fail.cpp

Modified: 
libcxx/trunk/test/libcxx/utilities/variant/variant.variant/variant.helper/variant_alternative.fail.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/utilities/variant/variant.variant/variant.helper/variant_alternative.fail.cpp?rev=305198&r1=305197&r2=305198&view=diff
==
--- 
libcxx/trunk/test/libcxx/utilities/variant/variant.variant/variant.helper/variant_alternative.fail.cpp
 (original)
+++ 
libcxx/trunk/test/libcxx/utilities/variant/variant.variant/variant.helper/variant_alternative.fail.cpp
 Mon Jun 12 11:33:41 2017
@@ -7,7 +7,9 @@
 //
 
//===--===//
 
-// 
+// 
+// UNSUPPORTED: c++98, c++03, c++11, c++14
+
 
 // template  struct variant_alternative; // undefined
 // template  struct variant_alternative;


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


[PATCH] D33102: [clang] Implement -Wcast-qual for C++

2017-06-12 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

So i'm trying to analyze that stage2 warning.
The testcase //seems// to be: (autogenerated all the variants)

  void test_nop() {
unsigned char **ptr1 = 0;
void **ptr2 = (void **)ptr1;
  }
  void test_bad() {
unsigned char **ptr1 = 0;
const void **ptr2 = (const void **)ptr1; // expected-warning {{cast from 
'unsigned char **' to 'const void **' must have all intermediate pointers const 
qualified to be safe}}
  }
  void test_good0() {
unsigned char **ptr1 = 0;
void *const *ptr2 = (void *const *)ptr1;
  }
  void test_good1() {
unsigned char **ptr1 = 0;
const void *const *ptr2 = (const void *const *)ptr1;
  }
  void test_good2() {
unsigned char *const *ptr1 = 0;
void *const *ptr2 = (void *const *)ptr1;
  }
  void test_good3() {
unsigned char *const *ptr1 = 0;
const void *const *ptr2 = (const void *const *)ptr1;
  }
  void test_good4() {
const unsigned char **ptr1 = 0;
const void **ptr2 = (const void **)ptr1;
  }
  void test_good5() {
const unsigned char **ptr1 = 0;
const void *const *ptr2 = (const void *const *)ptr1;
  }
  void test_good6() {
const unsigned char *const *ptr1 = 0;
const void *const *ptr2 = (const void *const *)ptr1;
  }

GCC does not warn about such code at all, clang in C mode does warn about only 
one combination:

  $ gcc -c /tmp/test.c -Wcast-qual
  $ echo $?
  0
  $ clang -c /tmp/test.c -Wcast-qual
  /tmp/test.c:7:38: warning: cast from 'unsigned char **' to 'const void **' 
must have all intermediate pointers const qualified to be safe [-Wcast-qual]
const void **ptr2 = (const void **)ptr1; // expected-warning {{cast from 
'unsigned char **' to 'const void **' must have all intermediate pointers const 
qualified to be safe}}
   ^
  1 warning generated.

David, you reviewed the original `-Wcast-qual` patch, does all that ^ make 
sense?

F3429854: gen.cpp 


Repository:
  rL LLVM

https://reviews.llvm.org/D33102



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


Re: [PATCH] D33102: [clang] Implement -Wcast-qual for C++

2017-06-12 Thread David Blaikie via cfe-commits
On Mon, Jun 12, 2017 at 10:10 AM Roman Lebedev via Phabricator <
revi...@reviews.llvm.org> wrote:

> lebedev.ri added a comment.
>
> So i'm trying to analyze that stage2 warning.
>

Could you link to the buildbot failure to see the original LLVM project
code triggering this situation?


> The testcase //seems// to be: (autogenerated all the variants)
>
>   void test_nop() {
> unsigned char **ptr1 = 0;
> void **ptr2 = (void **)ptr1;
>   }
>   void test_bad() {
> unsigned char **ptr1 = 0;
> const void **ptr2 = (const void **)ptr1; // expected-warning {{cast
> from 'unsigned char **' to 'const void **' must have all intermediate
> pointers const qualified to be safe}}
>   }
>   void test_good0() {
> unsigned char **ptr1 = 0;
> void *const *ptr2 = (void *const *)ptr1;
>   }
>   void test_good1() {
> unsigned char **ptr1 = 0;
> const void *const *ptr2 = (const void *const *)ptr1;
>   }
>   void test_good2() {
> unsigned char *const *ptr1 = 0;
> void *const *ptr2 = (void *const *)ptr1;
>   }
>   void test_good3() {
> unsigned char *const *ptr1 = 0;
> const void *const *ptr2 = (const void *const *)ptr1;
>   }
>   void test_good4() {
> const unsigned char **ptr1 = 0;
> const void **ptr2 = (const void **)ptr1;
>   }
>   void test_good5() {
> const unsigned char **ptr1 = 0;
> const void *const *ptr2 = (const void *const *)ptr1;
>   }
>   void test_good6() {
> const unsigned char *const *ptr1 = 0;
> const void *const *ptr2 = (const void *const *)ptr1;
>   }
>
> GCC does not warn about such code at all, clang in C mode does warn about
> only one combination:
>
>   $ gcc -c /tmp/test.c -Wcast-qual
>   $ echo $?
>   0
>   $ clang -c /tmp/test.c -Wcast-qual
>   /tmp/test.c:7:38: warning: cast from 'unsigned char **' to 'const void
> **' must have all intermediate pointers const qualified to be safe
> [-Wcast-qual]
> const void **ptr2 = (const void **)ptr1; // expected-warning {{cast
> from 'unsigned char **' to 'const void **' must have all intermediate
> pointers const qualified to be safe}}
>^
>   1 warning generated.
>
> David, you reviewed the original `-Wcast-qual` patch, does all that ^ make
> sense?
>

That seems like a reasonable warning, do you agree?

But maybe it's best to put it under another flag name so it doesn't collide
with GCC.

But really - *shrug* I'd probably leave it under the same flag, fix the
LLVM project code that causes it, and carry on.


>
> F3429854: gen.cpp 
>
>
> Repository:
>   rL LLVM
>
> https://reviews.llvm.org/D33102
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D33102: [clang] Implement -Wcast-qual for C++

2017-06-12 Thread Roman Lebedev via cfe-commits
On Mon, Jun 12, 2017 at 8:16 PM, David Blaikie  wrote:
>
>
> On Mon, Jun 12, 2017 at 10:10 AM Roman Lebedev via Phabricator
>  wrote:
>>
>> lebedev.ri added a comment.
>>
>> So i'm trying to analyze that stage2 warning.
>
>
> Could you link to the buildbot failure to see the original LLVM project code
> triggering this situation?
http://lab.llvm.org:8011/builders/clang-with-lto-ubuntu/builds/3249
http://lab.llvm.org:8011/builders/clang-with-lto-ubuntu/builds/3249/steps/build-stage2-LLVMgold.so/logs/stdio

FAILED: 
/home/buildbot/Buildbot/Slave1a/clang-with-lto-ubuntu/install/stage1/bin/clang++
  -DGTEST_HAS_RTTI=0 -DLLVM_BUILD_GLOBAL_ISEL -D_DEBUG -D_GNU_SOURCE
-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
-Ilib/CodeGen/AsmPrinter
-I/home/buildbot/Buildbot/Slave1a/clang-with-lto-ubuntu/llvm.src/lib/CodeGen/AsmPrinter
-Iinclude 
-I/home/buildbot/Buildbot/Slave1a/clang-with-lto-ubuntu/llvm.src/include
-fPIC -fvisibility-inlines-hidden -Werror -Werror=date-time -std=c++11
-Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual
-Wmissing-field-initializers -pedantic -Wno-long-long
-Wcovered-switch-default -Wnon-virtual-dtor -Wdelete-non-virtual-dtor
-Wstring-conversion -fcolor-diagnostics -ffunction-sections
-fdata-sections -O3-UNDEBUG  -fno-exceptions -fno-rtti -MMD -MT
lib/CodeGen/AsmPrinter/CMakeFiles/LLVMAsmPrinter.dir/CodeViewDebug.cpp.o
-MF lib/CodeGen/AsmPrinter/CMakeFiles/LLVMAsmPrinter.dir/CodeViewDebug.cpp.o.d
-o lib/CodeGen/AsmPrinter/CMakeFiles/LLVMAsmPrinter.dir/CodeViewDebug.cpp.o
-c 
/home/buildbot/Buildbot/Slave1a/clang-with-lto-ubuntu/llvm.src/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
In file included from
/home/buildbot/Buildbot/Slave1a/clang-with-lto-ubuntu/llvm.src/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp:14:
In file included from
/home/buildbot/Buildbot/Slave1a/clang-with-lto-ubuntu/llvm.src/lib/CodeGen/AsmPrinter/CodeViewDebug.h:17:
In file included from
/home/buildbot/Buildbot/Slave1a/clang-with-lto-ubuntu/llvm.src/lib/CodeGen/AsmPrinter/DbgValueHistoryCalculator.h:15:
In file included from
/home/buildbot/Buildbot/Slave1a/clang-with-lto-ubuntu/llvm.src/include/llvm/IR/DebugInfoMetadata.h:26:
In file included from
/home/buildbot/Buildbot/Slave1a/clang-with-lto-ubuntu/llvm.src/include/llvm/IR/Metadata.h:23:
/home/buildbot/Buildbot/Slave1a/clang-with-lto-ubuntu/llvm.src/include/llvm/ADT/PointerUnion.h:161:19:
error: cast from 'void **' to 'const llvm::DISubprogram **' must have
all intermediate pointers const qualified to be safe
[-Werror,-Wcast-qual]
return (PT1 *)Val.getAddrOfPointer();
  ^
/home/buildbot/Buildbot/Slave1a/clang-with-lto-ubuntu/llvm.src/include/llvm/ADT/TinyPtrVector.h:177:18:
note: in instantiation of member function 'llvm::PointerUnion
*>::getAddrOfPtr1' requested here
  return Val.getAddrOfPtr1();
 ^
/home/buildbot/Buildbot/Slave1a/clang-with-lto-ubuntu/llvm.src/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp:1885:33:
note: in instantiation of member function 'llvm::TinyPtrVector::begin' requested here
for (const DISubprogram *SP : MethodItr.second) {
^


>>
>> The testcase //seems// to be: (autogenerated all the variants)
>>
>>   void test_nop() {
>> unsigned char **ptr1 = 0;
>> void **ptr2 = (void **)ptr1;
>>   }
>>   void test_bad() {
>> unsigned char **ptr1 = 0;
>> const void **ptr2 = (const void **)ptr1; // expected-warning {{cast
>> from 'unsigned char **' to 'const void **' must have all intermediate
>> pointers const qualified to be safe}}
>>   }
>>   void test_good0() {
>> unsigned char **ptr1 = 0;
>> void *const *ptr2 = (void *const *)ptr1;
>>   }
>>   void test_good1() {
>> unsigned char **ptr1 = 0;
>> const void *const *ptr2 = (const void *const *)ptr1;
>>   }
>>   void test_good2() {
>> unsigned char *const *ptr1 = 0;
>> void *const *ptr2 = (void *const *)ptr1;
>>   }
>>   void test_good3() {
>> unsigned char *const *ptr1 = 0;
>> const void *const *ptr2 = (const void *const *)ptr1;
>>   }
>>   void test_good4() {
>> const unsigned char **ptr1 = 0;
>> const void **ptr2 = (const void **)ptr1;
>>   }
>>   void test_good5() {
>> const unsigned char **ptr1 = 0;
>> const void *const *ptr2 = (const void *const *)ptr1;
>>   }
>>   void test_good6() {
>> const unsigned char *const *ptr1 = 0;
>> const void *const *ptr2 = (const void *const *)ptr1;
>>   }
>>
>> GCC does not warn about such code at all, clang in C mode does warn about
>> only one combination:
>>
>>   $ gcc -c /tmp/test.c -Wcast-qual
>>   $ echo $?
>>   0
>>   $ clang -c /tmp/test.c -Wcast-qual
>>   /tmp/test.c:7:38: warning: cast from 'unsigned char **' to 'const void
>> **' must have all intermediate pointers const qualified to be safe
>> [-Wcast-qual]
>> const void **ptr2 = (const void **)ptr1; // expected-warning {{cast
>> from 'unsigned char **' to 'const void **' must have all intermediate
>> pointers const qualified to be sa

r305207 - [Sema] Use the right FoldingSet.

2017-06-12 Thread George Burgess IV via cfe-commits
Author: gbiv
Date: Mon Jun 12 12:44:30 2017
New Revision: 305207

URL: http://llvm.org/viewvc/llvm-project?rev=305207&view=rev
Log:
[Sema] Use the right FoldingSet.

We were doing FindNodeOrInsertPos on SubstTemplateTypeParmPackTypes, so
we should presumably be inserting into SubstTemplateTypeParmPackTypes.

Looks like the FoldingSet API can be tweaked a bit so that we can catch
things like this at compile-time. I'll look into that shortly.

I'm unsure of how to test this; suggestions welcome.

Thanks to Vladimir Voskresensky for bringing this up!

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

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=305207&r1=305206&r2=305207&view=diff
==
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Mon Jun 12 12:44:30 2017
@@ -3565,7 +3565,7 @@ QualType ASTContext::getSubstTemplateTyp
 = new (*this, TypeAlignment) SubstTemplateTypeParmPackType(Parm, Canon,
ArgPack);
   Types.push_back(SubstParm);
-  SubstTemplateTypeParmTypes.InsertNode(SubstParm, InsertPos);
+  SubstTemplateTypeParmPackTypes.InsertNode(SubstParm, InsertPos);
   return QualType(SubstParm, 0);  
 }
 


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


[PATCH] D33904: Add a __has_attribute_enhancement macro to clang

2017-06-12 Thread George Burgess IV via Phabricator via cfe-commits
george.burgess.iv added a comment.

> Why not just use __has_feature(overloadable_unmarked) or similar?

My impression was that `__has_feature` was was for larger features than tweaks 
to attributes. If this would be an appropriate use of `__has_feature`, though, 
I'm happy to keep things simple.

I'll update the other review with `__has_feature`. If it goes in with that, 
I'll abandon this.

Thanks!




Comment at: docs/LanguageExtensions.rst:176
+For example, clang's ``overloadable`` attribute has existed since before Clang
+3.5, but in Clang 5.0 it gained was modified to support so-called "unmarked
+overloads".  One can use ``__has_attribute_enhancement`` to query whether clang

ahatanak wrote:
> Do you need "gained" here?
Good catch :)


https://reviews.llvm.org/D33904



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


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

2017-06-12 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 102204.
yaxunl marked an inline comment as done.
yaxunl added a comment.

Add TargetInfo::getTargetConstantAddressSpace.


https://reviews.llvm.org/D33842

Files:
  include/clang/Basic/TargetInfo.h
  lib/Basic/Targets.cpp
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/TargetInfo.cpp
  test/CodeGen/address-space.c
  test/CodeGen/default-address-space.c
  test/CodeGenCXX/amdgcn-automatic-variable.cpp
  test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp

Index: test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp
===
--- test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp
+++ test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -std=c++11 -triple x86_64-none-linux-gnu -emit-llvm -o - %s | FileCheck %s
+// RUN1: %clang_cc1 -std=c++11 -triple x86_64-none-linux-gnu -emit-llvm -o - %s | FileCheck -check-prefixes=X86,CHECK %s
+// RUN: %clang_cc1 -std=c++11 -triple amdgcn-amd-amdhsa-amdgiz -DNO_TLS -emit-llvm -o - %s | FileCheck -check-prefixes=AMD,CHECK %s
 
 namespace std {
   typedef decltype(sizeof(int)) size_t;
@@ -46,62 +47,82 @@
   wantslist1(std::initializer_list);
   ~wantslist1();
 };
-
-// CHECK: @_ZGR15globalInitList1_ = internal constant [3 x i32] [i32 1, i32 2, i32 3]
-// CHECK: @globalInitList1 = global %{{[^ ]+}} { i32* getelementptr inbounds ([3 x i32], [3 x i32]* @_ZGR15globalInitList1_, i32 0, i32 0), i{{32|64}} 3 }
+// X86: @_ZGR15globalInitList1_ = internal constant [3 x i32] [i32 1, i32 2, i32 3]
+// X86: @globalInitList1 = global %{{[^ ]+}} { i32* getelementptr inbounds ([3 x i32], [3 x i32]* @_ZGR15globalInitList1_, i32 0, i32 0), i{{32|64}} 3 }
+// AMD: @_ZGR15globalInitList1_ = internal addrspace(1) constant [3 x i32] [i32 1, i32 2, i32 3]
+// AMD: @globalInitList1 = addrspace(1) global %{{[^ ]+}} { i32* addrspacecast (i32 addrspace(1)* getelementptr inbounds ([3 x i32], [3 x i32] addrspace(1)* @_ZGR15globalInitList1_, i32 0, i32 0) to i32*), i{{32|64}} 3 }
 std::initializer_list globalInitList1 = {1, 2, 3};
 
+#ifndef NO_TLS
 namespace thread_local_global_array {
   // FIXME: We should be able to constant-evaluate this even though the
   // initializer is not a constant expression (pointers to thread_local
   // objects aren't really a problem).
   //
-  // CHECK: @_ZN25thread_local_global_array1xE = thread_local global
-  // CHECK: @_ZGRN25thread_local_global_array1xE_ = internal thread_local constant [4 x i32] [i32 1, i32 2, i32 3, i32 4]
+  // X86: @_ZN25thread_local_global_array1xE = thread_local global
+  // X86: @_ZGRN25thread_local_global_array1xE_ = internal thread_local constant [4 x i32] [i32 1, i32 2, i32 3, i32 4]
   std::initializer_list thread_local x = { 1, 2, 3, 4 };
 }
-
-// CHECK: @globalInitList2 = global %{{[^ ]+}} zeroinitializer
-// CHECK: @_ZGR15globalInitList2_ = internal global [2 x %[[WITHARG:[^ ]*]]] zeroinitializer
-
-// CHECK: @_ZN15partly_constant1kE = global i32 0, align 4
-// CHECK: @_ZN15partly_constant2ilE = global {{.*}} null, align 8
-// CHECK: @[[PARTLY_CONSTANT_OUTER:_ZGRN15partly_constant2ilE.*]] = internal global {{.*}} zeroinitializer, align 8
-// CHECK: @[[PARTLY_CONSTANT_INNER:_ZGRN15partly_constant2ilE.*]] = internal global [3 x {{.*}}] zeroinitializer, align 8
-// CHECK: @[[PARTLY_CONSTANT_FIRST:_ZGRN15partly_constant2ilE.*]] = internal constant [3 x i32] [i32 1, i32 2, i32 3], align 4
-// CHECK: @[[PARTLY_CONSTANT_SECOND:_ZGRN15partly_constant2ilE.*]] = internal global [2 x i32] zeroinitializer, align 4
-// CHECK: @[[PARTLY_CONSTANT_THIRD:_ZGRN15partly_constant2ilE.*]] = internal constant [4 x i32] [i32 5, i32 6, i32 7, i32 8], align 4
-
-// CHECK: @[[REFTMP1:.*]] = private constant [2 x i32] [i32 42, i32 43], align 4
-// CHECK: @[[REFTMP2:.*]] = private constant [3 x %{{.*}}] [%{{.*}} { i32 1 }, %{{.*}} { i32 2 }, %{{.*}} { i32 3 }], align 4
+#endif
+
+// X86: @globalInitList2 = global %{{[^ ]+}} zeroinitializer
+// X86: @_ZGR15globalInitList2_ = internal global [2 x %[[WITHARG:[^ ]*]]] zeroinitializer
+// AMD: @globalInitList2 = addrspace(1) global %{{[^ ]+}} zeroinitializer
+// AMD: @_ZGR15globalInitList2_ = internal addrspace(1) global [2 x %[[WITHARG:[^ ]*]]] zeroinitializer
+
+// X86: @_ZN15partly_constant1kE = global i32 0, align 4
+// X86: @_ZN15partly_constant2ilE = global {{.*}} null, align 8
+// X86: @[[PARTLY_CONSTANT_OUTER:_ZGRN15partly_constant2ilE.*]] = internal global {{.*}} zeroinitializer, align 8
+// X86: @[[PARTLY_CONSTANT_INNER:_ZGRN15partly_constant2ilE.*]] = internal global [3 x {{.*}}] zeroinitializer, align 8
+// X86: @[[PARTLY_CONSTANT_FIRST:_ZGRN15partly_constant2ilE.*]] = internal constant [3 x i32] [i32 1, i32 2, i32 3], align 4
+// X86: @[[PARTLY_CONSTANT_SECOND:_ZGRN15partly_constant2ilE.*]] = internal global [2 x i32] zeroinitializer, align 4
+// X86: @[[PARTLY_CONSTANT_THIRD:_ZGRN15partly_constant2ilE.*]] = internal constant [4 x i32]

r305211 - [analyzer] Fix a crash when an ObjC object is constructed in AllocaRegion.

2017-06-12 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Mon Jun 12 12:59:50 2017
New Revision: 305211

URL: http://llvm.org/viewvc/llvm-project?rev=305211&view=rev
Log:
[analyzer] Fix a crash when an ObjC object is constructed in AllocaRegion.

Memory region allocated by alloca() carries no implicit type information.
Don't crash when resolving the init message for an Objective-C object
that is being constructed in such region.

rdar://problem/32517077

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

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
cfe/trunk/test/Analysis/DynamicTypePropagation.m

Modified: cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp?rev=305211&r1=305210&r2=305211&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp Mon Jun 12 12:59:50 2017
@@ -957,6 +957,12 @@ RuntimeDefinition ObjCMethodCall::getRun
 return RuntimeDefinition();
 
   DynamicTypeInfo DTI = getDynamicTypeInfo(getState(), Receiver);
+  if (!DTI.isValid()) {
+assert(isa(Receiver) &&
+   "Unhandled untyped region class!");
+return RuntimeDefinition();
+  }
+
   QualType DynType = DTI.getType();
   CanBeSubClassed = DTI.canBeASubClass();
   ReceiverT = dyn_cast(DynType.getCanonicalType());

Modified: cfe/trunk/test/Analysis/DynamicTypePropagation.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/DynamicTypePropagation.m?rev=305211&r1=305210&r2=305211&view=diff
==
--- cfe/trunk/test/Analysis/DynamicTypePropagation.m (original)
+++ cfe/trunk/test/Analysis/DynamicTypePropagation.m Mon Jun 12 12:59:50 2017
@@ -4,6 +4,9 @@
 #  error Compiler does not support Objective-C generics?
 #endif
 
+typedef __typeof(sizeof(int)) size_t;
+void *memset(void *, int, size_t);
+
 #define nil 0
 typedef unsigned long NSUInteger;
 typedef int BOOL;
@@ -21,6 +24,7 @@ __attribute__((objc_root_class))
 @end
 
 @interface NSArray : NSObject
+- (void) init;
 - (BOOL)contains:(ObjectType)obj;
 - (ObjectType)getObjAtIndex:(NSUInteger)idx;
 - (ObjectType)objectAtIndexedSubscript:(NSUInteger)idx;
@@ -55,3 +59,11 @@ void testArgument(NSArray *arr
   // MyType!
   [element myFunction:0 myParam:0 ];
 }
+
+// Do not try this at home! The analyzer shouldn't crash though when it
+// tries to figure out the dynamic type behind the alloca's return value.
+void testAlloca(size_t NSArrayClassSizeWeKnowSomehow) {
+  NSArray *arr = __builtin_alloca(NSArrayClassSizeWeKnowSomehow);
+  memset(arr, 0, NSArrayClassSizeWeKnowSomehow);
+  [arr init]; // no-crash
+}


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


[PATCH] D33828: [analyzer] Don't crash when the code tries to construct an Objective-C object in AllocaRegion.

2017-06-12 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL305211: [analyzer] Fix a crash when an ObjC object is 
constructed in AllocaRegion. (authored by dergachev).

Changed prior to commit:
  https://reviews.llvm.org/D33828?vs=101401&id=102206#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D33828

Files:
  cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
  cfe/trunk/test/Analysis/DynamicTypePropagation.m


Index: cfe/trunk/test/Analysis/DynamicTypePropagation.m
===
--- cfe/trunk/test/Analysis/DynamicTypePropagation.m
+++ cfe/trunk/test/Analysis/DynamicTypePropagation.m
@@ -4,6 +4,9 @@
 #  error Compiler does not support Objective-C generics?
 #endif
 
+typedef __typeof(sizeof(int)) size_t;
+void *memset(void *, int, size_t);
+
 #define nil 0
 typedef unsigned long NSUInteger;
 typedef int BOOL;
@@ -21,6 +24,7 @@
 @end
 
 @interface NSArray : NSObject
+- (void) init;
 - (BOOL)contains:(ObjectType)obj;
 - (ObjectType)getObjAtIndex:(NSUInteger)idx;
 - (ObjectType)objectAtIndexedSubscript:(NSUInteger)idx;
@@ -55,3 +59,11 @@
   // MyType!
   [element myFunction:0 myParam:0 ];
 }
+
+// Do not try this at home! The analyzer shouldn't crash though when it
+// tries to figure out the dynamic type behind the alloca's return value.
+void testAlloca(size_t NSArrayClassSizeWeKnowSomehow) {
+  NSArray *arr = __builtin_alloca(NSArrayClassSizeWeKnowSomehow);
+  memset(arr, 0, NSArrayClassSizeWeKnowSomehow);
+  [arr init]; // no-crash
+}
Index: cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
@@ -957,6 +957,12 @@
 return RuntimeDefinition();
 
   DynamicTypeInfo DTI = getDynamicTypeInfo(getState(), Receiver);
+  if (!DTI.isValid()) {
+assert(isa(Receiver) &&
+   "Unhandled untyped region class!");
+return RuntimeDefinition();
+  }
+
   QualType DynType = DTI.getType();
   CanBeSubClassed = DTI.canBeASubClass();
   ReceiverT = dyn_cast(DynType.getCanonicalType());


Index: cfe/trunk/test/Analysis/DynamicTypePropagation.m
===
--- cfe/trunk/test/Analysis/DynamicTypePropagation.m
+++ cfe/trunk/test/Analysis/DynamicTypePropagation.m
@@ -4,6 +4,9 @@
 #  error Compiler does not support Objective-C generics?
 #endif
 
+typedef __typeof(sizeof(int)) size_t;
+void *memset(void *, int, size_t);
+
 #define nil 0
 typedef unsigned long NSUInteger;
 typedef int BOOL;
@@ -21,6 +24,7 @@
 @end
 
 @interface NSArray : NSObject
+- (void) init;
 - (BOOL)contains:(ObjectType)obj;
 - (ObjectType)getObjAtIndex:(NSUInteger)idx;
 - (ObjectType)objectAtIndexedSubscript:(NSUInteger)idx;
@@ -55,3 +59,11 @@
   // MyType!
   [element myFunction:0 myParam:0 ];
 }
+
+// Do not try this at home! The analyzer shouldn't crash though when it
+// tries to figure out the dynamic type behind the alloca's return value.
+void testAlloca(size_t NSArrayClassSizeWeKnowSomehow) {
+  NSArray *arr = __builtin_alloca(NSArrayClassSizeWeKnowSomehow);
+  memset(arr, 0, NSArrayClassSizeWeKnowSomehow);
+  [arr init]; // no-crash
+}
Index: cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
@@ -957,6 +957,12 @@
 return RuntimeDefinition();
 
   DynamicTypeInfo DTI = getDynamicTypeInfo(getState(), Receiver);
+  if (!DTI.isValid()) {
+assert(isa(Receiver) &&
+   "Unhandled untyped region class!");
+return RuntimeDefinition();
+  }
+
   QualType DynType = DTI.getType();
   CanBeSubClassed = DTI.canBeASubClass();
   ReceiverT = dyn_cast(DynType.getCanonicalType());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r305213 - Add regression test for r305179.

2017-06-12 Thread Yaron Keren via cfe-commits
Author: yrnkrn
Date: Mon Jun 12 13:05:13 2017
New Revision: 305213

URL: http://llvm.org/viewvc/llvm-project?rev=305213&view=rev
Log:
Add regression test for r305179.


Added:
cfe/trunk/test/Misc/pr32207.c

Added: cfe/trunk/test/Misc/pr32207.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/pr32207.c?rev=305213&view=auto
==
--- cfe/trunk/test/Misc/pr32207.c (added)
+++ cfe/trunk/test/Misc/pr32207.c Mon Jun 12 13:05:13 2017
@@ -0,0 +1,3 @@
+// test for r305179
+// RUN: %clang_cc1 -emit-llvm -O -mllvm -print-after-all %s -o %t 2>&1 | grep 
'*** IR Dump After Function Integration/Inlining ***'
+void foo() {}


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


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

2017-06-12 Thread George Burgess IV via Phabricator via cfe-commits
george.burgess.iv updated this revision to Diff 102207.
george.burgess.iv added a comment.

Swap to using `__has_feature(overloadable_unmarked)` for detection, as 
recommended by Hal in https://reviews.llvm.org/D33904


https://reviews.llvm.org/D32332

Files:
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Sema.h
  lib/Lex/PPMacroExpansion.cpp
  lib/Sema/SemaDecl.cpp
  test/CodeGen/mangle-ms.c
  test/CodeGen/mangle.c
  test/CodeGenCXX/mangle-ms.cpp
  test/PCH/attrs.c
  test/Sema/overloadable.c

Index: test/Sema/overloadable.c
===
--- test/Sema/overloadable.c
+++ test/Sema/overloadable.c
@@ -3,12 +3,15 @@
 int var __attribute__((overloadable)); // expected-error{{'overloadable' attribute only applies to functions}}
 void params(void) __attribute__((overloadable(12))); // expected-error {{'overloadable' attribute takes no arguments}}
 
-int *f(int) __attribute__((overloadable)); // expected-note 2{{previous overload of function is here}}
-float *f(float); // expected-error{{overloaded function 'f' must have the 'overloadable' attribute}}
+int *f(int) __attribute__((overloadable)); // expected-note{{previous overload of function is here}}
+float *f(float);
 int *f(int); // expected-error{{redeclaration of 'f' must have the 'overloadable' attribute}} \
  // expected-note{{previous declaration is here}}
 double *f(double) __attribute__((overloadable)); // okay, new
 
+// Ensure we don't complain about overloadable on implicitly declared functions.
+int isdigit(int) __attribute__((overloadable));
+
 void test_f(int iv, float fv, double dv) {
   int *ip = f(iv);
   float *fp = f(fv);
@@ -71,19 +74,19 @@
   f1();
 }
 
-void before_local_1(int) __attribute__((overloadable)); // expected-note {{here}}
+void before_local_1(int) __attribute__((overloadable));
 void before_local_2(int); // expected-note {{here}}
 void before_local_3(int) __attribute__((overloadable));
 void local() {
-  void before_local_1(char); // expected-error {{must have the 'overloadable' attribute}}
-  void before_local_2(char) __attribute__((overloadable)); // expected-error {{conflicting types}}
+  void before_local_1(char);
+  void before_local_2(char); // expected-error {{conflicting types}}
   void before_local_3(char) __attribute__((overloadable));
-  void after_local_1(char); // expected-note {{here}}
-  void after_local_2(char) __attribute__((overloadable)); // expected-note {{here}}
+  void after_local_1(char);
+  void after_local_2(char) __attribute__((overloadable));
   void after_local_3(char) __attribute__((overloadable));
 }
-void after_local_1(int) __attribute__((overloadable)); // expected-error {{conflicting types}}
-void after_local_2(int); // expected-error {{must have the 'overloadable' attribute}}
+void after_local_1(int) __attribute__((overloadable));
+void after_local_2(int);
 void after_local_3(int) __attribute__((overloadable));
 
 // Make sure we allow C-specific conversions in C.
@@ -106,8 +109,8 @@
   void foo(char *c) __attribute__((overloadable));
   void (*ptr1)(void *) = &foo;
   void (*ptr2)(char *) = &foo;
-  void (*ambiguous)(int *) = &foo; // expected-error{{initializing 'void (*)(int *)' with an expression of incompatible type ''}} expected-note@105{{candidate function}} expected-note@106{{candidate function}}
-  void *vp_ambiguous = &foo; // expected-error{{initializing 'void *' with an expression of incompatible type ''}} expected-note@105{{candidate function}} expected-note@106{{candidate function}}
+  void (*ambiguous)(int *) = &foo; // expected-error{{initializing 'void (*)(int *)' with an expression of incompatible type ''}} expected-note@-4{{candidate function}} expected-note@-3{{candidate function}}
+  void *vp_ambiguous = &foo; // expected-error{{initializing 'void *' with an expression of incompatible type ''}} expected-note@-5{{candidate function}} expected-note@-4{{candidate function}}
 
   void (*specific1)(int *) = (void (*)(void *))&foo; // expected-warning{{incompatible function pointer types initializing 'void (*)(int *)' with an expression of type 'void (*)(void *)'}}
   void *specific2 = (void (*)(void *))&foo;
@@ -117,8 +120,8 @@
   void disabled(char *c) __attribute__((overloadable, enable_if(1, "The function name lies.")));
   // To be clear, these should all point to the last overload of 'disabled'
   void (*dptr1)(char *c) = &disabled;
-  void (*dptr2)(void *c) = &disabled; // expected-warning{{incompatible pointer types initializing 'void (*)(void *)' with an expression of type ''}} expected-note@115{{candidate function made ineligible by enable_if}} expected-note@116{{candidate function made ineligible by enable_if}} expected-note@117{{candidate function has type mismatch at 1st parameter (expected 'void *' but has 'char *')}}
-  void (*dptr3)(int *c) = &disabled; // expected-warning{{incompatible pointer types initializing 'void (*)(int *)' with an expressi

[PATCH] D33478: [libclang] When getting platform availabilities, merge multiple declarations if possible

2017-06-12 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

Thanks, I'll recommit today.


https://reviews.llvm.org/D33478



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


RE: r284060 - Implement MS _BitScan intrinsics

2017-06-12 Thread Erik Schwiebert via cfe-commits
Any more thoughts on this from Saleem or Apple folks?

Thanks,
Schwieb

From: Erik Schwiebert
Sent: Thursday, June 8, 2017 12:22 PM
To: 'Saleem Abdulrasool' ; 'Duncan P. N. Exon Smith' 

Cc: 'Albert Gutowski' ; 'Reid Kleckner' 
; 'David Majnemer' ; 'cfe-commits' 

Subject: RE: r284060 - Implement MS _BitScan intrinsics

It’s probably also better to not try to infer our weird desired behavior. It 
should probably be controlled by a specific driver directive, like 
“-fms-extensions-lp64-intrinsics” or something like that. Using a new directive 
means that nobody can accidentally get this behavior if they for some reason do 
want LLP64 behavior with Windows intrinsics.

Schwieb

From: Erik Schwiebert
Sent: Thursday, June 8, 2017 10:29 AM
To: 'Saleem Abdulrasool' mailto:compn...@compnerd.org>>; 
Duncan P. N. Exon Smith mailto:dexonsm...@apple.com>>
Cc: Albert Gutowski mailto:agutow...@google.com>>; Reid 
Kleckner mailto:r...@google.com>>; David Majnemer 
mailto:david.majne...@gmail.com>>; cfe-commits 
mailto:cfe-commits@lists.llvm.org>>
Subject: RE: r284060 - Implement MS _BitScan intrinsics

Yes, we definitely do not want to introduce pointer-type incompatibility 
warnings. Predicating the behavior change on LP64 vs LLP64 seems better.

What’s the best way to do that?  Brian and I can hack on clang a bit, but we’re 
certainly not experts.

Schwieb

From: Saleem Abdulrasool [mailto:compn...@compnerd.org]
Sent: Wednesday, June 7, 2017 7:32 PM
To: Duncan P. N. Exon Smith mailto:dexonsm...@apple.com>>
Cc: Albert Gutowski mailto:agutow...@google.com>>; Reid 
Kleckner mailto:r...@google.com>>; David Majnemer 
mailto:david.majne...@gmail.com>>; cfe-commits 
mailto:cfe-commits@lists.llvm.org>>; Erik 
Schwiebert mailto:eri...@microsoft.com>>
Subject: Re: r284060 - Implement MS _BitScan intrinsics

I'm worried about changing this signature all the time.  I suspect that it will 
cause the following to be emitted for valid code:

warning: incompatible pointer types passing 'unsigned long *' to parameter of 
type 'unsigned int *' [-Wincompatible-pointer-types]

Switching the signature on LP64 sounds much better to me.

On Wed, Jun 7, 2017 at 2:56 PM, Duncan P. N. Exon Smith via cfe-commits 
mailto:cfe-commits@lists.llvm.org>> wrote:
[... excuse the necromancy...]

Hi Albert (and Reid and David),

This commit is breaking some uses of -fms-extensions on Apple platforms.  In 
particular, Brian and Erik (CC'ed) build against a version of the Windows SDK 
on Apple platforms.  _BitScanReverse is expected to be 32-bit, matching 
Windows/LLP64, even though long is 64-bit on Darwin/LP64.

One idea we've had for fixing this is to use "int" instead of "long" for these 
intrinsics, either:
- all the time, or
- when in LP64 mode (e.g., Darwin + -fms-extensions).

Any other ideas?

Thanks,
Duncan

> On Oct 12, 2016, at 15:01, Albert Gutowski via cfe-commits 
> mailto:cfe-commits@lists.llvm.org>> wrote:
>
> Author: agutowski
> Date: Wed Oct 12 17:01:05 2016
> New Revision: 284060
>
> URL: 
> http://llvm.org/viewvc/llvm-project?rev=284060&view=rev
> Log:
> Implement MS _BitScan intrinsics
>
> Summary: _BitScan intrinsics (and some others, for example _Interlocked and 
> _bittest) are supposed to work on both ARM and x86. This is an attempt to 
> isolate them, avoiding repeating their code or writing separate function for 
> each builtin.
>
> Reviewers: hans, thakis, rnk, majnemer
>
> Subscribers: RKSimon, cfe-commits, aemerson
>
> Differential Revision: 
> https://reviews.llvm.org/D25264
>
> Modified:
>cfe/trunk/include/clang/Basic/BuiltinsARM.def
>cfe/trunk/include/clang/Basic/BuiltinsX86.def
>cfe/trunk/include/clang/Basic/BuiltinsX86_64.def
>cfe/trunk/lib/Basic/Targets.cpp
>cfe/trunk/lib/CodeGen/CGBuiltin.cpp
>cfe/trunk/lib/CodeGen/CodeGenFunction.h
>cfe/trunk/lib/Headers/intrin.h
>cfe/trunk/test/CodeGen/ms-intrinsics.c
>
> Modified: cfe/trunk/include/clang/Basic/BuiltinsARM.def
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsARM.def?rev=284060&r1=284059&r2=284060&view=diff

Re: r305213 - Add regression test for r305179.

2017-06-12 Thread David Blaikie via cfe-commits
Prefer FileCheck over grep, generally?

On Mon, Jun 12, 2017 at 11:05 AM Yaron Keren via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: yrnkrn
> Date: Mon Jun 12 13:05:13 2017
> New Revision: 305213
>
> URL: http://llvm.org/viewvc/llvm-project?rev=305213&view=rev
> Log:
> Add regression test for r305179.
>
>
> Added:
> cfe/trunk/test/Misc/pr32207.c
>
> Added: cfe/trunk/test/Misc/pr32207.c
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/pr32207.c?rev=305213&view=auto
>
> ==
> --- cfe/trunk/test/Misc/pr32207.c (added)
> +++ cfe/trunk/test/Misc/pr32207.c Mon Jun 12 13:05:13 2017
> @@ -0,0 +1,3 @@
> +// test for r305179
> +// RUN: %clang_cc1 -emit-llvm -O -mllvm -print-after-all %s -o %t 2>&1 |
> grep '*** IR Dump After Function Integration/Inlining ***'
> +void foo() {}
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r305215 - Address David Blaikie comment by replacing grep with FileCheck.

2017-06-12 Thread Yaron Keren via cfe-commits
Author: yrnkrn
Date: Mon Jun 12 13:29:37 2017
New Revision: 305215

URL: http://llvm.org/viewvc/llvm-project?rev=305215&view=rev
Log:
Address David Blaikie comment by replacing grep with FileCheck.


Modified:
cfe/trunk/test/Misc/pr32207.c

Modified: cfe/trunk/test/Misc/pr32207.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/pr32207.c?rev=305215&r1=305214&r2=305215&view=diff
==
--- cfe/trunk/test/Misc/pr32207.c (original)
+++ cfe/trunk/test/Misc/pr32207.c Mon Jun 12 13:29:37 2017
@@ -1,3 +1,4 @@
 // test for r305179
-// RUN: %clang_cc1 -emit-llvm -O -mllvm -print-after-all %s -o %t 2>&1 | grep 
'*** IR Dump After Function Integration/Inlining ***'
+// RUN: %clang_cc1 -emit-llvm -O -mllvm -print-after-all %s -o %t 2>&1 | 
FileCheck %s
+// CHECK: *** IR Dump After Function Integration/Inlining ***
 void foo() {}


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


Re: r305213 - Add regression test for r305179.

2017-06-12 Thread Yaron Keren via cfe-commits
Sure, r305215.

‫בתאריך יום ב׳, 12 ביוני 2017 ב-21:21 מאת ‪David Blaikie‬‏ <‪
dblai...@gmail.com‬‏>:‬

> Prefer FileCheck over grep, generally?
>
> On Mon, Jun 12, 2017 at 11:05 AM Yaron Keren via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: yrnkrn
>> Date: Mon Jun 12 13:05:13 2017
>> New Revision: 305213
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=305213&view=rev
>> Log:
>> Add regression test for r305179.
>>
>>
>> Added:
>> cfe/trunk/test/Misc/pr32207.c
>>
>> Added: cfe/trunk/test/Misc/pr32207.c
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/pr32207.c?rev=305213&view=auto
>>
>> ==
>> --- cfe/trunk/test/Misc/pr32207.c (added)
>> +++ cfe/trunk/test/Misc/pr32207.c Mon Jun 12 13:05:13 2017
>> @@ -0,0 +1,3 @@
>> +// test for r305179
>> +// RUN: %clang_cc1 -emit-llvm -O -mllvm -print-after-all %s -o %t 2>&1 |
>> grep '*** IR Dump After Function Integration/Inlining ***'
>> +void foo() {}
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r305213 - Add regression test for r305179.

2017-06-12 Thread Yaron Keren via cfe-commits
Should also fix this bot failure

http://green.lab.llvm.org/green/job/clang-stage1-cmake-RA-incremental_check/37468/testReport/junit/Clang/Misc/pr32207_c/


‫בתאריך יום ב׳, 12 ביוני 2017 ב-21:30 מאת ‪Yaron Keren‬‏ <‪
yaron.ke...@gmail.com‬‏>:‬

> Sure, r305215.
>
> ‫בתאריך יום ב׳, 12 ביוני 2017 ב-21:21 מאת ‪David Blaikie‬‏ <‪
> dblai...@gmail.com‬‏>:‬
>
>> Prefer FileCheck over grep, generally?
>>
>> On Mon, Jun 12, 2017 at 11:05 AM Yaron Keren via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>> Author: yrnkrn
>>> Date: Mon Jun 12 13:05:13 2017
>>> New Revision: 305213
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=305213&view=rev
>>> Log:
>>> Add regression test for r305179.
>>>
>>>
>>> Added:
>>> cfe/trunk/test/Misc/pr32207.c
>>>
>>> Added: cfe/trunk/test/Misc/pr32207.c
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/pr32207.c?rev=305213&view=auto
>>>
>>> ==
>>> --- cfe/trunk/test/Misc/pr32207.c (added)
>>> +++ cfe/trunk/test/Misc/pr32207.c Mon Jun 12 13:05:13 2017
>>> @@ -0,0 +1,3 @@
>>> +// test for r305179
>>> +// RUN: %clang_cc1 -emit-llvm -O -mllvm -print-after-all %s -o %t 2>&1
>>> | grep '*** IR Dump After Function Integration/Inlining ***'
>>> +void foo() {}
>>>
>>>
>>> ___
>>> cfe-commits mailing list
>>> cfe-commits@lists.llvm.org
>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>>
>>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D33910: [ubsan] Detect invalid unsigned pointer index expression (clang)

2017-06-12 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL305216: [ubsan] Detect invalid unsigned pointer index 
expression (clang) (authored by vedantk).

Changed prior to commit:
  https://reviews.llvm.org/D33910?vs=101479&id=102214#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D33910

Files:
  cfe/trunk/lib/CodeGen/CGExpr.cpp
  cfe/trunk/lib/CodeGen/CGExprScalar.cpp
  cfe/trunk/lib/CodeGen/CodeGenFunction.h
  cfe/trunk/test/CodeGen/ubsan-pointer-overflow.m

Index: cfe/trunk/test/CodeGen/ubsan-pointer-overflow.m
===
--- cfe/trunk/test/CodeGen/ubsan-pointer-overflow.m
+++ cfe/trunk/test/CodeGen/ubsan-pointer-overflow.m
@@ -5,47 +5,66 @@
   // CHECK:  [[BASE:%.*]] = ptrtoint i8* {{.*}} to i64, !nosanitize
   // CHECK-NEXT: [[COMPGEP:%.*]] = add i64 [[BASE]], 1, !nosanitize
   // CHECK-NEXT: [[POSVALID:%.*]] = icmp uge i64 [[COMPGEP]], [[BASE]], !nosanitize
-  // CHECK-NEXT: [[NEGVALID:%.*]] = icmp ult i64 [[COMPGEP]], [[BASE]], !nosanitize
-  // CHECK-NEXT: [[DIFFVALID:%.*]] = select i1 true, i1 [[POSVALID]], i1 [[NEGVALID]], !nosanitize
-  // CHECK-NEXT: [[VALID:%.*]] = and i1 true, [[DIFFVALID]], !nosanitize
-  // CHECK-NEXT: br i1 [[VALID]]{{.*}}, !nosanitize
+  // CHECK-NEXT: br i1 [[POSVALID]]{{.*}}, !nosanitize
   // CHECK: call void @__ubsan_handle_pointer_overflow{{.*}}, i64 [[BASE]], i64 [[COMPGEP]]){{.*}}, !nosanitize
   ++p;
 
   // CHECK: ptrtoint i8* {{.*}} to i64, !nosanitize
   // CHECK-NEXT: add i64 {{.*}}, -1, !nosanitize
   // CHECK: select i1 false{{.*}}, !nosanitize
-  // CHECK-NEXT: and i1 true{{.*}}, !nosanitize
   // CHECK: call void @__ubsan_handle_pointer_overflow{{.*}}
   --p;
 
+  // CHECK-NOT: select
   // CHECK: call void @__ubsan_handle_pointer_overflow{{.*}}
   p++;
 
+  // CHECK: select
   // CHECK: call void @__ubsan_handle_pointer_overflow{{.*}}
   p--;
 }
 
 // CHECK-LABEL: define void @binary_arith
 void binary_arith(char *p, int i) {
   // CHECK: [[SMUL:%.*]] = call { i64, i1 } @llvm.smul.with.overflow.i64(i64 1, i64 %{{.*}}), !nosanitize
   // CHECK-NEXT: [[SMULOFLOW:%.*]] = extractvalue { i64, i1 } [[SMUL]], 1, !nosanitize
-  // CHECK-NEXT: [[OFFSETOFLOW:%.*]] = or i1 false, [[SMULOFLOW]], !nosanitize
   // CHECK-NEXT: [[SMULVAL:%.*]] = extractvalue { i64, i1 } [[SMUL]], 0, !nosanitize
   // CHECK-NEXT: [[BASE:%.*]] = ptrtoint i8* {{.*}} to i64, !nosanitize
   // CHECK-NEXT: [[COMPGEP:%.*]] = add i64 [[BASE]], [[SMULVAL]], !nosanitize
+  // CHECK-NEXT: [[OFFSETVALID:%.*]] = xor i1 [[SMULOFLOW]], true, !nosanitize
   // CHECK-NEXT: [[POSVALID:%.*]] = icmp uge i64 [[COMPGEP]], [[BASE]], !nosanitize
-  // CHECK-NEXT: [[NEGVALID:%.*]] = icmp ult i64 [[COMPGEP]], [[BASE]], !nosanitize
   // CHECK-NEXT: [[POSOFFSET:%.*]] = icmp sge i64 [[SMULVAL]], 0, !nosanitize
-  // CHECK-DAG: [[OFFSETVALID:%.*]] = xor i1 [[OFFSETOFLOW]], true, !nosanitize
-  // CHECK-DAG: [[DIFFVALID:%.*]] = select i1 [[POSOFFSET]], i1 [[POSVALID]], i1 [[NEGVALID]], !nosanitize
-  // CHECK: [[VALID:%.*]] = and i1 [[OFFSETVALID]], [[DIFFVALID]], !nosanitize
+  // CHECK-NEXT: [[NEGVALID:%.*]] = icmp ult i64 [[COMPGEP]], [[BASE]], !nosanitize
+  // CHECK-NEXT: [[DIFFVALID:%.*]] = select i1 [[POSOFFSET]], i1 [[POSVALID]], i1 [[NEGVALID]], !nosanitize
+  // CHECK: [[VALID:%.*]] = and i1 [[DIFFVALID]], [[OFFSETVALID]], !nosanitize
   // CHECK-NEXT: br i1 [[VALID]]{{.*}}, !nosanitize
   // CHECK: call void @__ubsan_handle_pointer_overflow{{.*}}, i64 [[BASE]], i64 [[COMPGEP]]){{.*}}, !nosanitize
   p + i;
 
   // CHECK: [[OFFSET:%.*]] = sub i64 0, {{.*}}
   // CHECK-NEXT: getelementptr inbounds {{.*}} [[OFFSET]]
+  // CHECK: select
+  // CHECK: call void @__ubsan_handle_pointer_overflow{{.*}}
+  p - i;
+}
+
+// CHECK-LABEL: define void @binary_arith_unsigned
+void binary_arith_unsigned(char *p, unsigned i) {
+  // CHECK: [[SMUL:%.*]] = call { i64, i1 } @llvm.smul.with.overflow.i64(i64 1, i64 %{{.*}}), !nosanitize
+  // CHECK-NEXT: [[SMULOFLOW:%.*]] = extractvalue { i64, i1 } [[SMUL]], 1, !nosanitize
+  // CHECK-NEXT: [[SMULVAL:%.*]] = extractvalue { i64, i1 } [[SMUL]], 0, !nosanitize
+  // CHECK-NEXT: [[BASE:%.*]] = ptrtoint i8* {{.*}} to i64, !nosanitize
+  // CHECK-NEXT: [[COMPGEP:%.*]] = add i64 [[BASE]], [[SMULVAL]], !nosanitize
+  // CHECK-NEXT: [[OFFSETVALID:%.*]] = xor i1 [[SMULOFLOW]], true, !nosanitize
+  // CHECK-NEXT: [[POSVALID:%.*]] = icmp uge i64 [[COMPGEP]], [[BASE]], !nosanitize
+  // CHECK: [[VALID:%.*]] = and i1 [[POSVALID]], [[OFFSETVALID]], !nosanitize
+  // CHECK-NEXT: br i1 [[VALID]]{{.*}}, !nosanitize
+  // CHECK: call void @__ubsan_handle_pointer_overflow{{.*}}, i64 [[BASE]], i64 [[COMPGEP]]){{.*}}, !nosanitize
+  p + i;
+
+  // CHECK: [[OFFSET:%.*]] = sub i64 0, {{.*}}
+  // CHECK-NEXT: getelementptr inbounds {{.*}} [[OFFSET]]
+  // CHECK: select
   // CHECK: call void @__ubsan_handle_pointer_overflow{{.*}}
   p - i;
 }
@@ -55,16 +74,15 @@
   // CHECK: getelementptr inbounds [10 x [

r305216 - [ubsan] Detect invalid unsigned pointer index expression (clang)

2017-06-12 Thread Vedant Kumar via cfe-commits
Author: vedantk
Date: Mon Jun 12 13:42:51 2017
New Revision: 305216

URL: http://llvm.org/viewvc/llvm-project?rev=305216&view=rev
Log:
[ubsan] Detect invalid unsigned pointer index expression (clang)

Adding an unsigned offset to a base pointer has undefined behavior if
the result of the expression would precede the base. An example from
@regehr:

  int foo(char *p, unsigned offset) {
return p + offset >= p; // This may be optimized to '1'.
  }

  foo(p, -1); // UB.

This patch extends the pointer overflow check in ubsan to detect invalid
unsigned pointer index expressions. It changes the instrumentation to
only permit non-negative offsets in pointer index expressions when all
of the GEP indices are unsigned.

Testing: check-llvm, check-clang run on a stage2, ubsan-instrumented
build.

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

Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/test/CodeGen/ubsan-pointer-overflow.m

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=305216&r1=305215&r2=305216&view=diff
==
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Mon Jun 12 13:42:51 2017
@@ -3002,10 +3002,11 @@ static llvm::Value *emitArraySubscriptGE
   llvm::Value *ptr,
   ArrayRef indices,
   bool inbounds,
+  bool signedIndices,
   SourceLocation loc,
 const llvm::Twine &name = "arrayidx") {
   if (inbounds) {
-return CGF.EmitCheckedInBoundsGEP(ptr, indices, loc, name);
+return CGF.EmitCheckedInBoundsGEP(ptr, indices, signedIndices, loc, name);
   } else {
 return CGF.Builder.CreateGEP(ptr, indices, name);
   }
@@ -3038,7 +3039,7 @@ static QualType getFixedSizeElementType(
 static Address emitArraySubscriptGEP(CodeGenFunction &CGF, Address addr,
  ArrayRef indices,
  QualType eltType, bool inbounds,
- SourceLocation loc,
+ bool signedIndices, SourceLocation loc,
  const llvm::Twine &name = "arrayidx") {
   // All the indices except that last must be zero.
 #ifndef NDEBUG
@@ -3058,8 +3059,8 @@ static Address emitArraySubscriptGEP(Cod
   CharUnits eltAlign =
 getArrayElementAlign(addr.getAlignment(), indices.back(), eltSize);
 
-  llvm::Value *eltPtr =
-emitArraySubscriptGEP(CGF, addr.getPointer(), indices, inbounds, loc, 
name);
+  llvm::Value *eltPtr = emitArraySubscriptGEP(
+  CGF, addr.getPointer(), indices, inbounds, signedIndices, loc, name);
   return Address(eltPtr, eltAlign);
 }
 
@@ -3069,6 +3070,7 @@ LValue CodeGenFunction::EmitArraySubscri
   // in lexical order (this complexity is, sadly, required by C++17).
   llvm::Value *IdxPre =
   (E->getLHS() == E->getIdx()) ? EmitScalarExpr(E->getIdx()) : nullptr;
+  bool SignedIndices = false;
   auto EmitIdxAfterBase = [&, IdxPre](bool Promote) -> llvm::Value * {
 auto *Idx = IdxPre;
 if (E->getLHS() != E->getIdx()) {
@@ -3078,6 +3080,7 @@ LValue CodeGenFunction::EmitArraySubscri
 
 QualType IdxTy = E->getIdx()->getType();
 bool IdxSigned = IdxTy->isSignedIntegerOrEnumerationType();
+SignedIndices |= IdxSigned;
 
 if (SanOpts.has(SanitizerKind::ArrayBounds))
   EmitBoundsCheck(E, E->getBase(), Idx, IdxTy, Accessed);
@@ -3113,7 +3116,7 @@ LValue CodeGenFunction::EmitArraySubscri
 
 QualType EltType = LV.getType()->castAs()->getElementType();
 Addr = emitArraySubscriptGEP(*this, Addr, Idx, EltType, /*inbounds*/ true,
- E->getExprLoc());
+ SignedIndices, E->getExprLoc());
 return MakeAddrLValue(Addr, EltType, LV.getBaseInfo());
   }
 
@@ -3142,7 +3145,7 @@ LValue CodeGenFunction::EmitArraySubscri
 
 Addr = emitArraySubscriptGEP(*this, Addr, Idx, vla->getElementType(),
  !getLangOpts().isSignedOverflowDefined(),
- E->getExprLoc());
+ SignedIndices, E->getExprLoc());
 
   } else if (const ObjCObjectType *OIT = 
E->getType()->getAs()){
 // Indexing over an interface, as in "NSString *P; P[4];"
@@ -3167,8 +3170,9 @@ LValue CodeGenFunction::EmitArraySubscri
 // Do the GEP.
 CharUnits EltAlign =
   getArrayElementAlign(Addr.getAlignment(), Idx, InterfaceSize);
-llvm::Value *EltPtr = emitArraySubscriptGEP(
-*this, Addr.getPointer(), ScaledIdx, false, E->getExprLoc());
+llvm::Value *EltPtr =
+emitArraySu

Re: [PATCH] D33102: [clang] Implement -Wcast-qual for C++

2017-06-12 Thread David Blaikie via cfe-commits
Yeah, looks like the UB is baked in pretty deep here, so it's not
reasonable to try to fix it just because of this.

I'd probably suggest trying making that cast in PointerUnion.h into a
reinterpret cast? Would that suffice to address the const issues? Otherwise
a const_cast + reinterpret_cast?



On Mon, Jun 12, 2017 at 10:35 AM Roman Lebedev  wrote:

> On Mon, Jun 12, 2017 at 8:16 PM, David Blaikie  wrote:
> >
> >
> > On Mon, Jun 12, 2017 at 10:10 AM Roman Lebedev via Phabricator
> >  wrote:
> >>
> >> lebedev.ri added a comment.
> >>
> >> So i'm trying to analyze that stage2 warning.
> >
> >
> > Could you link to the buildbot failure to see the original LLVM project
> code
> > triggering this situation?
> http://lab.llvm.org:8011/builders/clang-with-lto-ubuntu/builds/3249
>
> http://lab.llvm.org:8011/builders/clang-with-lto-ubuntu/builds/3249/steps/build-stage2-LLVMgold.so/logs/stdio
>
> FAILED:
> /home/buildbot/Buildbot/Slave1a/clang-with-lto-ubuntu/install/stage1/bin/clang++
>   -DGTEST_HAS_RTTI=0 -DLLVM_BUILD_GLOBAL_ISEL -D_DEBUG -D_GNU_SOURCE
> -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
> -Ilib/CodeGen/AsmPrinter
>
> -I/home/buildbot/Buildbot/Slave1a/clang-with-lto-ubuntu/llvm.src/lib/CodeGen/AsmPrinter
> -Iinclude
> -I/home/buildbot/Buildbot/Slave1a/clang-with-lto-ubuntu/llvm.src/include
> -fPIC -fvisibility-inlines-hidden -Werror -Werror=date-time -std=c++11
> -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual
> -Wmissing-field-initializers -pedantic -Wno-long-long
> -Wcovered-switch-default -Wnon-virtual-dtor -Wdelete-non-virtual-dtor
> -Wstring-conversion -fcolor-diagnostics -ffunction-sections
> -fdata-sections -O3-UNDEBUG  -fno-exceptions -fno-rtti -MMD -MT
> lib/CodeGen/AsmPrinter/CMakeFiles/LLVMAsmPrinter.dir/CodeViewDebug.cpp.o
> -MF
> lib/CodeGen/AsmPrinter/CMakeFiles/LLVMAsmPrinter.dir/CodeViewDebug.cpp.o.d
> -o lib/CodeGen/AsmPrinter/CMakeFiles/LLVMAsmPrinter.dir/CodeViewDebug.cpp.o
> -c
> /home/buildbot/Buildbot/Slave1a/clang-with-lto-ubuntu/llvm.src/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
> In file included from
>
> /home/buildbot/Buildbot/Slave1a/clang-with-lto-ubuntu/llvm.src/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp:14:
> In file included from
>
> /home/buildbot/Buildbot/Slave1a/clang-with-lto-ubuntu/llvm.src/lib/CodeGen/AsmPrinter/CodeViewDebug.h:17:
> In file included from
>
> /home/buildbot/Buildbot/Slave1a/clang-with-lto-ubuntu/llvm.src/lib/CodeGen/AsmPrinter/DbgValueHistoryCalculator.h:15:
> In file included from
>
> /home/buildbot/Buildbot/Slave1a/clang-with-lto-ubuntu/llvm.src/include/llvm/IR/DebugInfoMetadata.h:26:
> In file included from
>
> /home/buildbot/Buildbot/Slave1a/clang-with-lto-ubuntu/llvm.src/include/llvm/IR/Metadata.h:23:
>
> /home/buildbot/Buildbot/Slave1a/clang-with-lto-ubuntu/llvm.src/include/llvm/ADT/PointerUnion.h:161:19:
> error: cast from 'void **' to 'const llvm::DISubprogram **' must have
> all intermediate pointers const qualified to be safe
> [-Werror,-Wcast-qual]
> return (PT1 *)Val.getAddrOfPointer();
>   ^
>
> /home/buildbot/Buildbot/Slave1a/clang-with-lto-ubuntu/llvm.src/include/llvm/ADT/TinyPtrVector.h:177:18:
> note: in instantiation of member function 'llvm::PointerUnion llvm::DISubprogram *, llvm::SmallVector
> *>::getAddrOfPtr1' requested here
>   return Val.getAddrOfPtr1();
>  ^
>
> /home/buildbot/Buildbot/Slave1a/clang-with-lto-ubuntu/llvm.src/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp:1885:33:
> note: in instantiation of member function 'llvm::TinyPtrVector llvm::DISubprogram *>::begin' requested here
> for (const DISubprogram *SP : MethodItr.second) {
> ^
>
>
> >>
> >> The testcase //seems// to be: (autogenerated all the variants)
> >>
> >>   void test_nop() {
> >> unsigned char **ptr1 = 0;
> >> void **ptr2 = (void **)ptr1;
> >>   }
> >>   void test_bad() {
> >> unsigned char **ptr1 = 0;
> >> const void **ptr2 = (const void **)ptr1; // expected-warning {{cast
> >> from 'unsigned char **' to 'const void **' must have all intermediate
> >> pointers const qualified to be safe}}
> >>   }
> >>   void test_good0() {
> >> unsigned char **ptr1 = 0;
> >> void *const *ptr2 = (void *const *)ptr1;
> >>   }
> >>   void test_good1() {
> >> unsigned char **ptr1 = 0;
> >> const void *const *ptr2 = (const void *const *)ptr1;
> >>   }
> >>   void test_good2() {
> >> unsigned char *const *ptr1 = 0;
> >> void *const *ptr2 = (void *const *)ptr1;
> >>   }
> >>   void test_good3() {
> >> unsigned char *const *ptr1 = 0;
> >> const void *const *ptr2 = (const void *const *)ptr1;
> >>   }
> >>   void test_good4() {
> >> const unsigned char **ptr1 = 0;
> >> const void **ptr2 = (const void **)ptr1;
> >>   }
> >>   void test_good5() {
> >> const unsigned char **ptr1 = 0;
> >> const void *const *ptr2 = (const void *const *)ptr1;
> >>   }
> >>   void test_good6() {
> >> const unsigned char *co

Re: r305182 - Revert r305164/5/7.

2017-06-12 Thread David Blaikie via cfe-commits
hey Saleem - might be worth sending a cfe-dev email about what the general
direction/goals are here (may not need precommit review for every patch,
but just some sanity checking)

On Mon, Jun 12, 2017 at 1:08 AM Daniel Jasper via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: djasper
> Date: Mon Jun 12 03:08:18 2017
> New Revision: 305182
>
> URL: http://llvm.org/viewvc/llvm-project?rev=305182&view=rev
> Log:
> Revert r305164/5/7.
>
> cc1as does not currently access the "--" version of this flag. At the
> very least this needs to be fixed and proper test cases need to be
> added.
>
> Simple reproducer:
> clang -Wa,--compress-debug-sections /tmp/test.cc
>
> Result:
> error: unknown argument: '--compress-debug-sections'
>
> Removed:
> cfe/trunk/test/Driver/compress-noias.c
> Modified:
> cfe/trunk/include/clang/Driver/CC1Options.td
> cfe/trunk/include/clang/Driver/Options.td
> cfe/trunk/lib/Driver/ToolChains/Clang.cpp
> cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
> cfe/trunk/lib/Frontend/CompilerInvocation.cpp
> cfe/trunk/test/Driver/compress.c
> cfe/trunk/test/Driver/nozlibcompress.c
> cfe/trunk/tools/driver/cc1as_main.cpp
>
> Modified: cfe/trunk/include/clang/Driver/CC1Options.td
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=305182&r1=305181&r2=305182&view=diff
>
> ==
> --- cfe/trunk/include/clang/Driver/CC1Options.td (original)
> +++ cfe/trunk/include/clang/Driver/CC1Options.td Mon Jun 12 03:08:18 2017
> @@ -134,6 +134,7 @@ def migrator_no_finalize_removal : Flag<
>
>  
> //===--===//
>
>  let Flags = [CC1Option, CC1AsOption, NoDriverOption] in {
> +
>  def debug_info_kind_EQ : Joined<["-"], "debug-info-kind=">;
>  def debug_info_macro : Flag<["-"], "debug-info-macro">,
>HelpText<"Emit macro debug information">;
> @@ -143,16 +144,14 @@ def fdebug_compilation_dir : Separate<["
>HelpText<"The compilation directory to embed in the debug info.">;
>  def dwarf_debug_flags : Separate<["-"], "dwarf-debug-flags">,
>HelpText<"The string to embed in the Dwarf debug flags record.">;
> -def compress_debug_sections : Flag<["-"], "compress-debug-sections">,
> -HelpText<"DWARF debug sections compression">;
> -def compress_debug_sections_EQ : Flag<["-"], "compress-debug-sections=">,
> -HelpText<"DWARF debug sections compression type">;
>  def mno_exec_stack : Flag<["-"], "mnoexecstack">,
>HelpText<"Mark the file as not needing an executable stack">;
>  def massembler_fatal_warnings : Flag<["-"], "massembler-fatal-warnings">,
>HelpText<"Make assembler warnings fatal">;
>  def mrelax_relocations : Flag<["--"], "mrelax-relocations">,
>  HelpText<"Use relaxable elf relocations">;
> +def compress_debug_sections : Flag<["-"], "compress-debug-sections">,
> +HelpText<"Compress DWARF debug sections using zlib">;
>  def msave_temp_labels : Flag<["-"], "msave-temp-labels">,
>HelpText<"Save temporary labels in the symbol table. "
> "Note this may change .s semantics and shouldn't generally be
> used "
>
> Modified: cfe/trunk/include/clang/Driver/Options.td
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=305182&r1=305181&r2=305182&view=diff
>
> ==
> --- cfe/trunk/include/clang/Driver/Options.td (original)
> +++ cfe/trunk/include/clang/Driver/Options.td Mon Jun 12 03:08:18 2017
> @@ -1563,10 +1563,6 @@ def gdwarf_aranges : Flag<["-"], "gdwarf
>  def gmodules : Flag <["-"], "gmodules">, Group,
>HelpText<"Generate debug info with external references to clang modules"
> " or precompiled headers">;
> -def gz : Flag<["-"], "gz">, Group,
> -HelpText<"DWARF debug sections compression type">;
> -def gz_EQ : Joined<["-"], "gz=">, Group,
> -HelpText<"DWARF debug sections compression type">;
>  def headerpad__max__install__names : Joined<["-"],
> "headerpad_max_install_names">;
>  def help : Flag<["-", "--"], "help">, Flags<[CC1Option,CC1AsOption]>,
>HelpText<"Display available options">;
>
> Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=305182&r1=305181&r2=305182&view=diff
>
> ==
> --- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
> +++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Mon Jun 12 03:08:18 2017
> @@ -910,37 +910,6 @@ static void RenderDebugEnablingArgs(cons
>}
>  }
>
> -static void RenderDebugInfoCompressionArgs(const ArgList &Args,
> -   ArgStringList &CmdArgs,
> -   const Driver &D) {
> -  const Arg *A = Args.getLastArg(options::OPT_gz, options::OPT

Re: r297702 - [CodeGen][ObjC] Fix a bug where the type of an ivar wasn't encoded

2017-06-12 Thread Joerg Sonnenberger via cfe-commits
On Thu, Jun 01, 2017 at 05:58:41PM -0700, Akira Hatanaka wrote:
> It crashes when there is an anonymous ivar of a bitfield type.
> 
> @interface FormatScanner {
>   int : 1;
> }
> @end
> 
> @implementation FormatScanner
> @end
> 
> I'm not sure if the code above is valid or not, but out of curiosity,
> why would you want an anonymous bitfield variable?

It's a reduced test case. The original test case has a variable name in
it.

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


r305221 - Recommit r305117: [libclang] Merge multiple availability clauses when

2017-06-12 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Mon Jun 12 14:06:30 2017
New Revision: 305221

URL: http://llvm.org/viewvc/llvm-project?rev=305221&view=rev
Log:
Recommit r305117: [libclang] Merge multiple availability clauses when
getting the platform's availability

Patch by Ronald Wampler!

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

Modified:
cfe/trunk/test/Index/availability.c
cfe/trunk/tools/libclang/CIndex.cpp

Modified: cfe/trunk/test/Index/availability.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/availability.c?rev=305221&r1=305220&r2=305221&view=diff
==
--- cfe/trunk/test/Index/availability.c (original)
+++ cfe/trunk/test/Index/availability.c Mon Jun 12 14:06:30 2017
@@ -8,13 +8,15 @@ enum {
 
 enum {
   old_enum_plat
-} 
__attribute__((availability(macosx,introduced=10.4,deprecated=10.5,obsoleted=10.7)
+} 
__attribute__((availability(macosx,introduced=10.4,deprecated=10.5,obsoleted=10.7)));
 
-// RUN: c-index-test -test-load-source all %s > %t
-// RUN: FileCheck -check-prefix=CHECK-1 %s < %t
-// RUN: FileCheck -check-prefix=CHECK-2 %s < %t
-// CHECK-1: (ios, introduced=3.2, deprecated=4.1) 
-// CHECK-2: (macos, introduced=10.4, deprecated=10.5, obsoleted=10.7)
+void bar(void) __attribute__((availability(macosx,introduced=10.4))) 
__attribute__((availability(macosx,obsoleted=10.6))) 
__attribute__((availability(ios,introduced=3.2))) 
__attribute__((availability(macosx,deprecated=10.5,message="use foobar")));
 
-// CHECK-2: EnumConstantDecl=old_enum:6:3 (Definition) (deprecated)
-// CHECK-2: EnumConstantDecl=old_enum_plat:10:3 {{.*}} (macos, 
introduced=10.4, deprecated=10.5, obsoleted=10.7)
+void bar2(void) 
__attribute__((availability(macosx,introduced=10.4,deprecated=10.5,obsoleted=10.7)))
 __attribute__((availability(ios,introduced=3.2,deprecated=10.0))) 
__attribute__((availability(macosx,introduced=10.4,deprecated=10.5,obsoleted=10.7)))
 __attribute__((availability(ios,introduced=3.2,deprecated=10.0)));
+
+// RUN: c-index-test -test-load-source all %s | FileCheck %s
+// CHECK: FunctionDecl=foo:3:6{{.*}}(ios, introduced=3.2, deprecated=4.1) 
(macos, introduced=10.4, deprecated=10.5, obsoleted=10.7)
+// CHECK: EnumConstantDecl=old_enum:6:3 (Definition) (deprecated)
+// CHECK: EnumConstantDecl=old_enum_plat:10:3 {{.*}} (macos, introduced=10.4, 
deprecated=10.5, obsoleted=10.7)
+// CHECK: FunctionDecl=bar:13:6{{.*}}(ios, introduced=3.2) (macos, 
introduced=10.4, deprecated=10.5, obsoleted=10.6, message="use foobar")
+// CHECK: FunctionDecl=bar2:15:6{{.*}}(ios, introduced=3.2, deprecated=10.0) 
(macos, introduced=10.4, deprecated=10.5, obsoleted=10.7)

Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=305221&r1=305220&r2=305221&view=diff
==
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Mon Jun 12 14:06:30 2017
@@ -7216,15 +7216,11 @@ static CXVersion convertVersion(VersionT
   return Out;
 }
 
-static int getCursorPlatformAvailabilityForDecl(const Decl *D,
-int *always_deprecated,
-CXString *deprecated_message,
-int *always_unavailable,
-CXString *unavailable_message,
-   CXPlatformAvailability 
*availability,
-int availability_size) {
+static void getCursorPlatformAvailabilityForDecl(
+const Decl *D, int *always_deprecated, CXString *deprecated_message,
+int *always_unavailable, CXString *unavailable_message,
+SmallVectorImpl &AvailabilityAttrs) {
   bool HadAvailAttr = false;
-  int N = 0;
   for (auto A : D->attrs()) {
 if (DeprecatedAttr *Deprecated = dyn_cast(A)) {
   HadAvailAttr = true;
@@ -7236,7 +7232,7 @@ static int getCursorPlatformAvailability
   }
   continue;
 }
-
+
 if (UnavailableAttr *Unavailable = dyn_cast(A)) {
   HadAvailAttr = true;
   if (always_unavailable)
@@ -7247,38 +7243,71 @@ static int getCursorPlatformAvailability
   }
   continue;
 }
-
+
 if (AvailabilityAttr *Avail = dyn_cast(A)) {
+  AvailabilityAttrs.push_back(Avail);
   HadAvailAttr = true;
-  if (N < availability_size) {
-availability[N].Platform
-  = cxstring::createDup(Avail->getPlatform()->getName());
-availability[N].Introduced = convertVersion(Avail->getIntroduced());
-availability[N].Deprecated = convertVersion(Avail->getDeprecated());
-availability[N].Obsoleted = convertVersion(Avail->getObsoleted());
-availability[N].Unavailable = Avail->getUnavailable();
-availability[N].Message = cxstring::createDup(Avail->get

[PATCH] D33478: [libclang] When getting platform availabilities, merge multiple declarations if possible

2017-06-12 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

Recommitted in r305221.


https://reviews.llvm.org/D33478



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


[PATCH] D33910: [ubsan] Detect invalid unsigned pointer index expression (clang)

2017-06-12 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: cfe/trunk/lib/CodeGen/CGExprScalar.cpp:2666
+  bool isSigned = indexOperand->getType()->isSignedIntegerOrEnumerationType();
+  bool mayHaveNegativeGEPIndex = isSigned || isSubtraction;
+

This logic doesn't look quite right; what happens here if you write "p - 
SIZE_MAX"?


Repository:
  rL LLVM

https://reviews.llvm.org/D33910



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


[PATCH] D33852: Enable __declspec(selectany) on linux

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



Comment at: include/clang/Basic/Attr.td:2421
 
-def SelectAny : InheritableAttr, TargetSpecificAttr {
+def SelectAny : InheritableAttr, TargetSpecificAttr {
   let Spellings = [Declspec<"selectany">, GCC<"selectany">];

davide wrote:
> Prazek wrote:
> > majnemer wrote:
> > > selectany should work on targets other than "x86", "x86_64", "arm", 
> > > "thumb", etc. I think it is only necessary to require that it be a COFF 
> > > or ELF target.
> > Should we allow other OSes than Win32 and Linux?
> I guess everything ELF should be allowed.
Why not use weak_odr / linkonce_odr on MachO? Microsoft builds Office for Mac 
and I suspect they use `__declspec(selectany)`.


https://reviews.llvm.org/D33852



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


Re: r284060 - Implement MS _BitScan intrinsics

2017-06-12 Thread Reid Kleckner via cfe-commits
On Wed, Jun 7, 2017 at 7:31 PM, Saleem Abdulrasool 
wrote:

> I'm worried about changing this signature all the time.  I suspect that it
> will cause the following to be emitted for valid code:
>
> warning: incompatible pointer types passing 'unsigned long *' to parameter
> of type 'unsigned int *' [-Wincompatible-pointer-types]
>
> Switching the signature on LP64 sounds much better to me.
>

Right, we have to do this. It needs to be `long` on Windows.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r305224 - Correct debug info bit offset calculation for big-endian targets

2017-06-12 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Mon Jun 12 14:57:56 2017
New Revision: 305224

URL: http://llvm.org/viewvc/llvm-project?rev=305224&view=rev
Log:
Correct debug info bit offset calculation for big-endian targets

Summary:
The change "[CodeView] Implement support for bit fields in
Clang" (r274201, https://reviews.llvm.org/rL274201) broke the
calculation of bit offsets for the debug info describing bitfields on
big-endian targets.

Prior to commit r274201 the debug info for bitfields got their offsets
from the ASTRecordLayout in CGDebugInfo::CollectRecordFields(), the
current field offset was then passed on to
CGDebugInfo::CollectRecordNormalField() and used directly in the
DIDerivedType.

Since commit r274201, the bit offset ending up in the DIDerivedType no
longer comes directly from the ASTRecordLayout. Instead
CGDebugInfo::CollectRecordNormalField() calls the new method
CGDebugInfo::createBitFieldType(), which in turn calls
CodeGenTypes::getCGRecordLayout().getBitFieldInfo() to fetch a
CGBitFieldInfo describing the field. The 'Offset' member of
CGBitFieldInfo is then used to calculate the bit offset of the
DIDerivedType. Unfortunately the previous and current method of
calculating the bit offset are only equivalent for little endian
targets, as CGRecordLowering::setBitFieldInfo() reverses the bit
offsets for big endian targets as the last thing it does.

A simple reproducer for this error is the following module:

struct fields {
  unsigned a : 4;
  unsigned b : 4;
} flags = {0x0f, 0x1};

Compiled for Mips, with commit r274200 both the DIDerivedType bit
offsets on the IR-level and the DWARF information on the ELF-level
will have the expected values: the offsets of 'a' and 'b' are 0 and 4
respectively. With r274201 the offsets are switched to 4 and 0. By
noting that the static initialization of 'flags' in both cases is the
same, we can eliminate a change in record layout as the cause of the
change in the debug info. Also compiling this example with gcc,
produces the same record layout and debug info as commit r274200.

In order to restore the previous function we extend
CGDebugInfo::createBitFieldType() to compensate for the reversal done
in CGRecordLowering::setBitFieldInfo().

Patch by Frej Drejhammar!

Reviewers: cfe-commits, majnemer, rnk, aaboud, echristo, aprantl

Reviewed By: rnk, aprantl

Subscribers: aprantl, arichardson, frej

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

Added:
cfe/trunk/test/CodeGen/mips-debug-info-bitfield.c
Modified:
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=305224&r1=305223&r2=305224&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Mon Jun 12 14:57:56 2017
@@ -1041,7 +1041,13 @@ llvm::DIType *CGDebugInfo::createBitFiel
   assert(SizeInBits > 0 && "found named 0-width bitfield");
   uint64_t StorageOffsetInBits =
   CGM.getContext().toBits(BitFieldInfo.StorageOffset);
-  uint64_t OffsetInBits = StorageOffsetInBits + BitFieldInfo.Offset;
+  uint64_t Offset = BitFieldInfo.Offset;
+  // The bit offsets for big endian machines are reversed for big
+  // endian target, compensate for that as the DIDerivedType requires
+  // un-reversed offsets.
+  if (CGM.getDataLayout().isBigEndian())
+Offset = BitFieldInfo.StorageSize - BitFieldInfo.Size - Offset;
+  uint64_t OffsetInBits = StorageOffsetInBits + Offset;
   llvm::DINode::DIFlags Flags = getAccessFlag(BitFieldDecl->getAccess(), RD);
   return DBuilder.createBitFieldMemberType(
   RecordTy, Name, File, Line, SizeInBits, OffsetInBits, 
StorageOffsetInBits,

Added: cfe/trunk/test/CodeGen/mips-debug-info-bitfield.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/mips-debug-info-bitfield.c?rev=305224&view=auto
==
--- cfe/trunk/test/CodeGen/mips-debug-info-bitfield.c (added)
+++ cfe/trunk/test/CodeGen/mips-debug-info-bitfield.c Mon Jun 12 14:57:56 2017
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -x c -debug-info-kind=limited -triple mips-none-linux-gnu 
-emit-llvm -o - %s | FileCheck %s
+
+struct fields
+{
+  unsigned a : 4;
+  unsigned b : 4;
+} flags;
+
+// CHECK: !DIDerivedType(tag: DW_TAG_member,
+// CHECK-SAME: {{.*}}name: "a"
+// CHECK-NOT: {{.*}}offset:
+// CHECK-SAME: {{.*}}flags: DIFlagBitField
+
+// CHECK: !DIDerivedType(tag: DW_TAG_member,
+// CHECK-SAME: {{.*}}name: "b"
+// CHECK-SAME: {{.*}}offset: 4
+// CHECK-SAME: {{.*}}flags: DIFlagBitField


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


[PATCH] D32745: Correct debug info bit offset calculation for big-endian targets

2017-06-12 Thread Reid Kleckner via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL305224: Correct debug info bit offset calculation for 
big-endian targets (authored by rnk).

Changed prior to commit:
  https://reviews.llvm.org/D32745?vs=97773&id=102233#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D32745

Files:
  cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
  cfe/trunk/test/CodeGen/mips-debug-info-bitfield.c


Index: cfe/trunk/test/CodeGen/mips-debug-info-bitfield.c
===
--- cfe/trunk/test/CodeGen/mips-debug-info-bitfield.c
+++ cfe/trunk/test/CodeGen/mips-debug-info-bitfield.c
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -x c -debug-info-kind=limited -triple mips-none-linux-gnu 
-emit-llvm -o - %s | FileCheck %s
+
+struct fields
+{
+  unsigned a : 4;
+  unsigned b : 4;
+} flags;
+
+// CHECK: !DIDerivedType(tag: DW_TAG_member,
+// CHECK-SAME: {{.*}}name: "a"
+// CHECK-NOT: {{.*}}offset:
+// CHECK-SAME: {{.*}}flags: DIFlagBitField
+
+// CHECK: !DIDerivedType(tag: DW_TAG_member,
+// CHECK-SAME: {{.*}}name: "b"
+// CHECK-SAME: {{.*}}offset: 4
+// CHECK-SAME: {{.*}}flags: DIFlagBitField
Index: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
===
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
@@ -1041,7 +1041,13 @@
   assert(SizeInBits > 0 && "found named 0-width bitfield");
   uint64_t StorageOffsetInBits =
   CGM.getContext().toBits(BitFieldInfo.StorageOffset);
-  uint64_t OffsetInBits = StorageOffsetInBits + BitFieldInfo.Offset;
+  uint64_t Offset = BitFieldInfo.Offset;
+  // The bit offsets for big endian machines are reversed for big
+  // endian target, compensate for that as the DIDerivedType requires
+  // un-reversed offsets.
+  if (CGM.getDataLayout().isBigEndian())
+Offset = BitFieldInfo.StorageSize - BitFieldInfo.Size - Offset;
+  uint64_t OffsetInBits = StorageOffsetInBits + Offset;
   llvm::DINode::DIFlags Flags = getAccessFlag(BitFieldDecl->getAccess(), RD);
   return DBuilder.createBitFieldMemberType(
   RecordTy, Name, File, Line, SizeInBits, OffsetInBits, 
StorageOffsetInBits,


Index: cfe/trunk/test/CodeGen/mips-debug-info-bitfield.c
===
--- cfe/trunk/test/CodeGen/mips-debug-info-bitfield.c
+++ cfe/trunk/test/CodeGen/mips-debug-info-bitfield.c
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -x c -debug-info-kind=limited -triple mips-none-linux-gnu -emit-llvm -o - %s | FileCheck %s
+
+struct fields
+{
+  unsigned a : 4;
+  unsigned b : 4;
+} flags;
+
+// CHECK: !DIDerivedType(tag: DW_TAG_member,
+// CHECK-SAME: {{.*}}name: "a"
+// CHECK-NOT: {{.*}}offset:
+// CHECK-SAME: {{.*}}flags: DIFlagBitField
+
+// CHECK: !DIDerivedType(tag: DW_TAG_member,
+// CHECK-SAME: {{.*}}name: "b"
+// CHECK-SAME: {{.*}}offset: 4
+// CHECK-SAME: {{.*}}flags: DIFlagBitField
Index: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
===
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
@@ -1041,7 +1041,13 @@
   assert(SizeInBits > 0 && "found named 0-width bitfield");
   uint64_t StorageOffsetInBits =
   CGM.getContext().toBits(BitFieldInfo.StorageOffset);
-  uint64_t OffsetInBits = StorageOffsetInBits + BitFieldInfo.Offset;
+  uint64_t Offset = BitFieldInfo.Offset;
+  // The bit offsets for big endian machines are reversed for big
+  // endian target, compensate for that as the DIDerivedType requires
+  // un-reversed offsets.
+  if (CGM.getDataLayout().isBigEndian())
+Offset = BitFieldInfo.StorageSize - BitFieldInfo.Size - Offset;
+  uint64_t OffsetInBits = StorageOffsetInBits + Offset;
   llvm::DINode::DIFlags Flags = getAccessFlag(BitFieldDecl->getAccess(), RD);
   return DBuilder.createBitFieldMemberType(
   RecordTy, Name, File, Line, SizeInBits, OffsetInBits, StorageOffsetInBits,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r305227 - IR: Replace the "Linker Options" module flag with "llvm.linker.options" named metadata.

2017-06-12 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Mon Jun 12 15:10:48 2017
New Revision: 305227

URL: http://llvm.org/viewvc/llvm-project?rev=305227&view=rev
Log:
IR: Replace the "Linker Options" module flag with "llvm.linker.options" named 
metadata.

The new metadata is easier to manipulate than module flags.

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

Modified:
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.h
cfe/trunk/test/CodeGen/dependent-lib.c
cfe/trunk/test/CodeGen/linker-option.c
cfe/trunk/test/CodeGen/pragma-comment.c
cfe/trunk/test/CodeGen/pragma-detect_mismatch.c
cfe/trunk/test/CodeGenCXX/ms-thread_local.cpp
cfe/trunk/test/CodeGenObjC/availability-cf-link-guard.m
cfe/trunk/test/Modules/autolink.m
cfe/trunk/test/Modules/autolinkTBD.m
cfe/trunk/test/Modules/module-impl-with-link.c

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=305227&r1=305226&r2=305227&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Mon Jun 12 15:10:48 2017
@@ -1243,7 +1243,7 @@ void CodeGenModule::AddDependentLib(Stri
 /// \brief Add link options implied by the given module, including modules
 /// it depends on, using a postorder walk.
 static void addLinkOptionsPostorder(CodeGenModule &CGM, Module *Mod,
-SmallVectorImpl 
&Metadata,
+SmallVectorImpl &Metadata,
 llvm::SmallPtrSet &Visited) {
   // Import this module's parent.
   if (Mod->Parent && Visited.insert(Mod->Parent).second) {
@@ -1331,7 +1331,7 @@ void CodeGenModule::EmitModuleLinkOption
   // Add link options for all of the imported modules in reverse topological
   // order.  We don't do anything to try to order import link flags with 
respect
   // to linker options inserted by things like #pragma comment().
-  SmallVector MetadataArgs;
+  SmallVector MetadataArgs;
   Visited.clear();
   for (Module *M : LinkModules)
 if (Visited.insert(M).second)
@@ -1340,9 +1340,9 @@ void CodeGenModule::EmitModuleLinkOption
   LinkerOptionsMetadata.append(MetadataArgs.begin(), MetadataArgs.end());
 
   // Add the linker options metadata flag.
-  getModule().addModuleFlag(llvm::Module::AppendUnique, "Linker Options",
-llvm::MDNode::get(getLLVMContext(),
-  LinkerOptionsMetadata));
+  auto *NMD = getModule().getOrInsertNamedMetadata("llvm.linker.options");
+  for (auto *MD : LinkerOptionsMetadata)
+NMD->addOperand(MD);
 }
 
 void CodeGenModule::EmitDeferred() {

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=305227&r1=305226&r2=305227&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Mon Jun 12 15:10:48 2017
@@ -429,7 +429,7 @@ private:
   llvm::SmallPtrSet EmittedModuleInitializers;
 
   /// \brief A vector of metadata strings.
-  SmallVector LinkerOptionsMetadata;
+  SmallVector LinkerOptionsMetadata;
 
   /// @name Cache for Objective-C runtime types
   /// @{
@@ -1058,13 +1058,14 @@ public:
 
   void RefreshTypeCacheForClass(const CXXRecordDecl *Class);
 
-  /// \brief Appends Opts to the "Linker Options" metadata value.
+  /// \brief Appends Opts to the "llvm.linker.options" metadata value.
   void AppendLinkerOptions(StringRef Opts);
 
   /// \brief Appends a detect mismatch command to the linker options.
   void AddDetectMismatch(StringRef Name, StringRef Value);
 
-  /// \brief Appends a dependent lib to the "Linker Options" metadata value.
+  /// \brief Appends a dependent lib to the "llvm.linker.options" metadata
+  /// value.
   void AddDependentLib(StringRef Lib);
 
   llvm::GlobalVariable::LinkageTypes getFunctionLinkage(GlobalDecl GD);

Modified: cfe/trunk/test/CodeGen/dependent-lib.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/dependent-lib.c?rev=305227&r1=305226&r2=305227&view=diff
==
--- cfe/trunk/test/CodeGen/dependent-lib.c (original)
+++ cfe/trunk/test/CodeGen/dependent-lib.c Mon Jun 12 15:10:48 2017
@@ -3,14 +3,10 @@
 // RUN: %clang_cc1 %s --dependent-lib=msvcrt -triple x86_64-pc-win32 
-emit-llvm -o - | FileCheck %s
 // RUN: %clang_cc1 %s --dependent-lib=msvcrt -triple i686-pc-linux -emit-llvm 
-o - | FileCheck -check-prefix LINUX %s
 
-// CHECK: !llvm.module.flags = !{{{.*}}}
-// CHECK: !{{[0-9]+}} = !{i32 6, !"Linker Options", ![[link_opts:[0-9]+]]}
-// CHECK: ![[link_opts]] = !{![[msvcrt:[0-9]+]]}
+// CHECK: !llvm.linker.options = !{![[msvcrt:[0-9]+]]}
 // CHECK: ![[msvcrt]] = !{!"/DEFA

Re: [PATCH] D33910: [ubsan] Detect invalid unsigned pointer index expression (clang)

2017-06-12 Thread Vedant Kumar via cfe-commits

> On Jun 12, 2017, at 12:34 PM, Eli Friedman via Phabricator 
>  wrote:
> 
> efriedma added inline comments.
> 
> 
> 
> Comment at: cfe/trunk/lib/CodeGen/CGExprScalar.cpp:2666
> +  bool isSigned = 
> indexOperand->getType()->isSignedIntegerOrEnumerationType();
> +  bool mayHaveNegativeGEPIndex = isSigned || isSubtraction;
> +
> 
> This logic doesn't look quite right; what happens here if you write "p - 
> SIZE_MAX"?

This check is here in order to prevent false positives on expressions such as: 
"p - 1ULL".

We fail to diagnose the overflow in "p - SIZE_MAX" both before and after 
r305216 because we turn it into a GEP which does "p + 1" too early. 
EmitCheckedGEP doesn't "know" that it's invalid for the result of the GEP to be 
greater than "p". I'll file a bug about this.

vedant

> 
> 
> Repository:
>  rL LLVM
> 
> https://reviews.llvm.org/D33910
> 
> 
> 

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


[PATCH] D30375: Function with unparsed body is a definition

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

LGTM as-is, but a couple of questions for possible further improvements.




Comment at: lib/Sema/SemaDecl.cpp:12221
 FD->setBody(Body);
+FD->setWillHaveBody(false);
 

Would it make sense to leave this `true` for a defaulted function whose body 
has not yet been synthesized?



Comment at: lib/Sema/SemaTemplateInstantiateDecl.cpp:1812-1819
   // Check for a function body.
   const FunctionDecl *Definition = nullptr;
   if (Function->isDefined(Definition) &&
   Definition->getTemplateSpecializationKind() == TSK_Undeclared) {
 SemaRef.Diag(Function->getLocation(), diag::err_redefinition)
 << Function->getDeclName();
 SemaRef.Diag(Definition->getLocation(), 
diag::note_previous_definition);

 Can we replace this...



Comment at: lib/Sema/SemaTemplateInstantiateDecl.cpp:1841-1853
 // If some prior declaration of this function was a friend with an
 // uninstantiated definition, reject it.
 if (R->getFriendObjectKind()) {
   if (const FunctionDecl *RPattern =
   R->getTemplateInstantiationPattern()) {
 if (RPattern->isDefined(RPattern)) {
   SemaRef.Diag(Function->getLocation(), diag::err_redefinition)

... and this with

```
SemaRef.CheckForFunctionRedefinition(Function);
Function->setWillHaveBody(true);
```

?


https://reviews.llvm.org/D30375



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


[PATCH] D34107: [clangd] Allow to override contents of the file during completion.

2017-06-12 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir accepted this revision.
krasimir added inline comments.
This revision is now accepted and ready to land.



Comment at: unittests/clangd/ClangdTests.cpp:432
+  // size the same.
+  // We complete on the 3rd line(2nd in zero-based numbering), because raw
+  // string literal of the SourceContents starts with a newline(it's easy to

nit: add a space between `line` and `(`.



Comment at: unittests/clangd/ClangdTests.cpp:452
+  StringRef(OverridenSourceContents))
+.Value;
+EXPECT_TRUE(ContainsItem(CodeCompletionResultsOverriden, "cbc"));

Is this how clang-format formats this chain? :(


https://reviews.llvm.org/D34107



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


Re: [clang-tools-extra] r303735 - Modify test so that it looks for patterns in stderr as well

2017-06-12 Thread David Blaikie via cfe-commits
I've been seeing errors from this test recently:

Command Output (stderr):
--
1 error generated.
Error while processing
/usr/local/google/home/blaikie/dev/llvm/src/tools/clang/tools/extra/test/clang-tidy/diagnostic.cpp.nonexistent.cpp.
/usr/local/google/home/blaikie/dev/llvm/src/tools/clang/tools/extra/test/clang-tidy/diagnostic.cpp:10:12:
error: expected string not found in input
// CHECK2: :[[@LINE+2]]:9: warning: implicit conversion from 'double' to
'int' changes value from 1.5 to 1 [clang-diagnostic-literal-conversion]
   ^
:2:1: note: scanning from here
Skipping
/usr/local/google/home/blaikie/dev/llvm/src/tools/clang/tools/extra/test/clang-tidy/diagnostic.cpp.
Compile command not found.
^
:2:1: note: with expression "@LINE+2" equal to "12"
Skipping
/usr/local/google/home/blaikie/dev/llvm/src/tools/clang/tools/extra/test/clang-tidy/diagnostic.cpp.
Compile command not found.
^


Specifically, the output is:
$ ./bin/clang-tidy
-checks='-*,clang-diagnostic-*,google-explicit-constructor'
/usr/local/google/home/blaikie/dev/llvm/src/tools/clang/tools/extra/test/clang-tidy/diagnostic.cpp
-- -fan-unknown-option 2>&1error: unknown
argument: '-fan-unknown-option'
 Skipping
/usr/local/google/home/blaikie/dev/llvm/src/tools/clang/tools/extra/test/clang-tidy/diagnostic.cpp.
Compile command not found.


Does this look like it might be related to any of your changes in this
area? Perhaps the error due to unknown argument is causing clang-tidy not
to continue on to run the check & report the warning?


On Wed, May 24, 2017 at 3:51 AM Serge Pavlov via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: sepavloff
> Date: Wed May 24 05:50:56 2017
> New Revision: 303735
>
> URL: http://llvm.org/viewvc/llvm-project?rev=303735&view=rev
> Log:
> Modify test so that it looks for patterns in stderr as well
>
> With the change https://reviews.llvm.org/D33013 driver will not build
> compilation object if command line is invalid, in particular, if
> unrecognized option is provided. In such cases it will prints diagnostics
> on stderr. The test 'clang-tidy/diagnostic.cpp' checks reaction on
> unrecognized option and will fail when D33013 is applied because it checks
> only stdout for test patterns and expects the name of diagnostic category
> prepared by clang-tidy. With this change the test makes more general check
> and must work in either case.
>
> Differential Revision: https://reviews.llvm.org/D33173
>
> Modified:
> clang-tools-extra/trunk/test/clang-tidy/diagnostic.cpp
>
> Modified: clang-tools-extra/trunk/test/clang-tidy/diagnostic.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/diagnostic.cpp?rev=303735&r1=303734&r2=303735&view=diff
>
> ==
> --- clang-tools-extra/trunk/test/clang-tidy/diagnostic.cpp (original)
> +++ clang-tools-extra/trunk/test/clang-tidy/diagnostic.cpp Wed May 24
> 05:50:56 2017
> @@ -1,11 +1,11 @@
>  // RUN: clang-tidy -checks='-*,modernize-use-override' %s.nonexistent.cpp
> -- | FileCheck -check-prefix=CHECK1
> -implicit-check-not='{{warning:|error:}}' %s
> -// RUN: clang-tidy
> -checks='-*,clang-diagnostic-*,google-explicit-constructor' %s --
> -fan-unknown-option | FileCheck -check-prefix=CHECK2
> -implicit-check-not='{{warning:|error:}}' %s
> -// RUN: clang-tidy
> -checks='-*,google-explicit-constructor,clang-diagnostic-literal-conversion'
> %s -- -fan-unknown-option | FileCheck -check-prefix=CHECK3
> -implicit-check-not='{{warning:|error:}}' %s
> +// RUN: clang-tidy
> -checks='-*,clang-diagnostic-*,google-explicit-constructor' %s --
> -fan-unknown-option 2>&1 | FileCheck -check-prefix=CHECK2
> -implicit-check-not='{{warning:|error:}}' %s
> +// RUN: clang-tidy
> -checks='-*,google-explicit-constructor,clang-diagnostic-literal-conversion'
> %s -- -fan-unknown-option 2>&1 | FileCheck -check-prefix=CHECK3
> -implicit-check-not='{{warning:|error:}}' %s
>  // RUN: clang-tidy
> -checks='-*,modernize-use-override,clang-diagnostic-macro-redefined' %s --
> -DMACRO_FROM_COMMAND_LINE | FileCheck -check-prefix=CHECK4
> -implicit-check-not='{{warning:|error:}}' %s
>
>  // CHECK1: error: error reading '{{.*}}.nonexistent.cpp'
> [clang-diagnostic-error]
> -// CHECK2: error: unknown argument: '-fan-unknown-option'
> [clang-diagnostic-error]
> -// CHECK3: error: unknown argument: '-fan-unknown-option'
> [clang-diagnostic-error]
> +// CHECK2: error: unknown argument: '-fan-unknown-option'
> +// CHECK3: error: unknown argument: '-fan-unknown-option'
>
>  // CHECK2: :[[@LINE+2]]:9: warning: implicit conversion from 'double' to
> 'int' changes value from 1.5 to 1 [clang-diagnostic-literal-conversion]
>  // CHECK3: :[[@LINE+1]]:9: warning: implicit conversion from 'double' to
> 'int' changes value
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http:

Re: r284060 - Implement MS _BitScan intrinsics

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

> On Jun 12, 2017, at 12:44, Reid Kleckner  wrote:
> 
>> On Wed, Jun 7, 2017 at 7:31 PM, Saleem Abdulrasool  
>> wrote:
>> I'm worried about changing this signature all the time.  I suspect that it 
>> will cause the following to be emitted for valid code:
>> 
>> warning: incompatible pointer types passing 'unsigned long *' to parameter 
>> of type 'unsigned int *' [-Wincompatible-pointer-types]
>> 
>> Switching the signature on LP64 sounds much better to me.
> 
> Right, we have to do this. It needs to be `long` on Windows.

SGTM.  We'll go that way.

> On Jun 8, 2017, at 12:21, Erik Schwiebert  wrote:
> 
> It’s probably also better to not try to infer our weird desired behavior. It 
> should probably be controlled by a specific driver directive, like 
> “-fms-extensions-lp64-intrinsics” or something like that. Using a new 
> directive means that nobody can accidentally get this behavior if they for 
> some reason do want LLP64 behavior with Windows intrinsics.

This seems overly complicated.  Is there a customer that:
- is on LP64,
- is using -fms-extensions,
- is using these intrinsics, and
- wants them to be 64-bit longs instead of 32-bit ints?
Put another way: who would use these intrinsics on LP64 and *not* want to mimic 
LLP64?

If everyone using the intrinsics on LP64 is going to have to specify 
-fms-extensions-lp64-intrinsics, then we should just imply it.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


RE: r284060 - Implement MS _BitScan intrinsics

2017-06-12 Thread Erik Schwiebert via cfe-commits
SGTM too. Regarding Duncan's last question -- I can't think of any such 
customer. :) If you all think the right thing for clang to do is to infer LLP64 
behavior on LP64 (Darwin) + ms_extensions, then that is fine with me!

Thanks all!
Schwieb

-Original Message-
From: dexonsm...@apple.com [mailto:dexonsm...@apple.com] 
Sent: Monday, June 12, 2017 1:55 PM
To: Reid Kleckner 
Cc: Saleem Abdulrasool ; Albert Gutowski 
; David Majnemer ; cfe-commits 
; Erik Schwiebert 
Subject: Re: r284060 - Implement MS _BitScan intrinsics


> On Jun 12, 2017, at 12:44, Reid Kleckner  wrote:
> 
>> On Wed, Jun 7, 2017 at 7:31 PM, Saleem Abdulrasool  
>> wrote:
>> I'm worried about changing this signature all the time.  I suspect that it 
>> will cause the following to be emitted for valid code:
>> 
>> warning: incompatible pointer types passing 'unsigned long *' to parameter 
>> of type 'unsigned int *' [-Wincompatible-pointer-types]
>> 
>> Switching the signature on LP64 sounds much better to me.
> 
> Right, we have to do this. It needs to be `long` on Windows.

SGTM.  We'll go that way.

> On Jun 8, 2017, at 12:21, Erik Schwiebert  wrote:
> 
> It’s probably also better to not try to infer our weird desired behavior. It 
> should probably be controlled by a specific driver directive, like 
> “-fms-extensions-lp64-intrinsics” or something like that. Using a new 
> directive means that nobody can accidentally get this behavior if they for 
> some reason do want LLP64 behavior with Windows intrinsics.

This seems overly complicated.  Is there a customer that:
- is on LP64,
- is using -fms-extensions,
- is using these intrinsics, and
- wants them to be 64-bit longs instead of 32-bit ints?
Put another way: who would use these intrinsics on LP64 and *not* want to mimic 
LLP64?

If everyone using the intrinsics on LP64 is going to have to specify 
-fms-extensions-lp64-intrinsics, then we should just imply it.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r305233 - Revert r303316, a change to ExprConstant to evaluate function arguments.

2017-06-12 Thread Nick Lewycky via cfe-commits
Author: nicholas
Date: Mon Jun 12 16:15:44 2017
New Revision: 305233

URL: http://llvm.org/viewvc/llvm-project?rev=305233&view=rev
Log:
Revert r303316, a change to ExprConstant to evaluate function arguments.

The patch was itself correct but it uncovered other bugs which are going to be 
difficult to fix, per PR33140.

Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/Sema/integer-overflow.c

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=305233&r1=305232&r2=305233&view=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Mon Jun 12 16:15:44 2017
@@ -4588,7 +4588,7 @@ public:
   }
 
   bool handleCallExpr(const CallExpr *E, APValue &Result,
-  const LValue *ResultSlot) {
+ const LValue *ResultSlot) {
 const Expr *Callee = E->getCallee()->IgnoreParens();
 QualType CalleeType = Callee->getType();
 
@@ -4597,23 +4597,6 @@ public:
 auto Args = llvm::makeArrayRef(E->getArgs(), E->getNumArgs());
 bool HasQualifier = false;
 
-struct EvaluateIgnoredRAII {
-public:
-  EvaluateIgnoredRAII(EvalInfo &Info, llvm::ArrayRef ToEval)
-  : Info(Info), ToEval(ToEval) {}
-  ~EvaluateIgnoredRAII() {
-if (Info.noteFailure()) {
-  for (auto E : ToEval)
-EvaluateIgnoredValue(Info, E);
-}
-  }
-  void cancel() { ToEval = {}; }
-  void drop_front() { ToEval = ToEval.drop_front(); }
-private:
-  EvalInfo &Info;
-  llvm::ArrayRef ToEval;
-} EvalArguments(Info, Args);
-
 // Extract function decl and 'this' pointer from the callee.
 if (CalleeType->isSpecificBuiltinType(BuiltinType::BoundMember)) {
   const ValueDecl *Member = nullptr;
@@ -4663,12 +4646,10 @@ public:
 if (Args.empty())
   return Error(E);
 
-const Expr *FirstArg = Args[0];
-Args = Args.drop_front();
-EvalArguments.drop_front();
-if (!EvaluateObjectArgument(Info, FirstArg, ThisVal))
+if (!EvaluateObjectArgument(Info, Args[0], ThisVal))
   return false;
 This = &ThisVal;
+Args = Args.slice(1);
   } else if (MD && MD->isLambdaStaticInvoker()) {   
 // Map the static invoker for the lambda back to the call operator.
 // Conveniently, we don't have to slice out the 'this' argument (as is
@@ -4720,12 +4701,8 @@ public:
 const FunctionDecl *Definition = nullptr;
 Stmt *Body = FD->getBody(Definition);
 
-if (!CheckConstexprFunction(Info, E->getExprLoc(), FD, Definition, Body))
-  return false;
-
-EvalArguments.cancel();
-
-if (!HandleFunctionCall(E->getExprLoc(), Definition, This, Args, Body, 
Info,
+if (!CheckConstexprFunction(Info, E->getExprLoc(), FD, Definition, Body) ||
+!HandleFunctionCall(E->getExprLoc(), Definition, This, Args, Body, 
Info,
 Result, ResultSlot))
   return false;
 

Modified: cfe/trunk/test/Sema/integer-overflow.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/integer-overflow.c?rev=305233&r1=305232&r2=305233&view=diff
==
--- cfe/trunk/test/Sema/integer-overflow.c (original)
+++ cfe/trunk/test/Sema/integer-overflow.c Mon Jun 12 16:15:44 2017
@@ -151,14 +151,6 @@ uint64_t check_integer_overflows(int i)
   uint64_t *b;
   uint64_t b2 = b[4608 * 1024 * 1024] + 1;
 
-// expected-warning@+1 {{overflow in expression; result is 536870912 with type 
'int'}} 
-  f0(4608 * 1024 * 1024);
-  f0(4608ul * 1024 * 1024);
-// expected-warning@+1 2{{overflow in expression; result is 536870912 with 
type 'int'}} 
-  f1(4608 * 1024 * 1024, 4608 * 1024 * 1024);
-// expected-warning@+1 2{{overflow in expression; result is 536870912 with 
type 'int'}} 
-  f2(4608 * 1024 * 1024, 4608 * 1024 * 1024);
-
 // expected-warning@+1 2{{overflow in expression; result is 536870912 with 
type 'int'}}
   int j1 = i ? (4608 * 1024 * 1024) : (4608 * 1024 * 1024);
 


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


r305238 - [ODRHash] Add diagnostic messages for typedef and type alias.

2017-06-12 Thread Richard Trieu via cfe-commits
Author: rtrieu
Date: Mon Jun 12 16:58:22 2017
New Revision: 305238

URL: http://llvm.org/viewvc/llvm-project?rev=305238&view=rev
Log:
[ODRHash] Add diagnostic messages for typedef and type alias.

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

Modified: cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td?rev=305238&r1=305237&r2=305238&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td Mon Jun 12 
16:58:22 2017
@@ -121,10 +121,10 @@ def err_module_odr_violation_mismatch_de
   "%q0 has different definitions in different modules; first difference is "
   "%select{definition in module '%2'|defined here}1 found "
   "%select{end of class|public access specifier|private access specifier|"
-  "protected access specifier|static assert|field|method}3">;
+  "protected access specifier|static assert|field|method|type 
alias|typedef}3">;
 def note_module_odr_violation_mismatch_decl : Note<"but in '%0' found "
   "%select{end of class|public access specifier|private access specifier|"
-  "protected access specifier|static assert|field|method}1">;
+  "protected access specifier|static assert|field|method|type 
alias|typedef}1">;
 
 def err_module_odr_violation_mismatch_decl_diff : Error<
   "%q0 has different definitions in different modules; first difference is "
@@ -149,7 +149,9 @@ def err_module_odr_violation_mismatch_de
   "method %4 is %select{not inline|inline}5|"
   "method %4 that has %5 parameter%s5|"
   "method %4 with %ordinal5 parameter of type %6%select{| decayed from %8}7|"
-  "method %4 with %ordinal5 parameter named %6}3">;
+  "method %4 with %ordinal5 parameter named %6|"
+  "%select{typedef|type alias}4 name %5|"
+  "%select{typedef|type alias}4 %5 with underlying type %6}3">;
 
 def note_module_odr_violation_mismatch_decl_diff : Note<"but in '%0' found "
   "%select{"
@@ -172,15 +174,19 @@ def note_module_odr_violation_mismatch_d
   "method %2 is %select{not inline|inline}3|"
   "method %2 that has %3 parameter%s3|"
   "method %2 with %ordinal3 parameter of type %4%select{| decayed from %6}5|"
-  "method %2 with %ordinal3 parameter named %4}1">;
+  "method %2 with %ordinal3 parameter named %4|"
+  "%select{typedef|type alias}2 name %3|"
+  "%select{typedef|type alias}2 %3 with different underlying type %4}1">;
 
 def err_module_odr_violation_mismatch_decl_unknown : Error<
   "%q0 %select{with definition in module '%2'|defined here}1 has different "
   "definitions in different modules; first difference is this "
-  "%select{static assert|field|method|unexpected decl}3">;
+  "%select{static assert|field|method|type alias|typedef|"
+  "unexpected decl}3">;
 def note_module_odr_violation_mismatch_decl_unknown : Note<
   "but in '%0' found "
   "%select{different static assert|different field|different method|"
+  "different type alias|different typedef|"
   "another unexpected decl}1">;
 
 def warn_duplicate_module_file_extension : Warning<

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=305238&r1=305237&r2=305238&view=diff
==
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Mon Jun 12 16:58:22 2017
@@ -9242,6 +9242,7 @@ void ASTReader::diagnoseOdrViolations()
 
   // Used with err_module_odr_violation_mismatch_decl and
   // note_module_odr_violation_mismatch_decl
+  // This list should be the same Decl's as in ODRHash::isWhiteListedDecl
   enum {
 EndOfClass,
 PublicSpecifer,
@@ -9250,6 +9251,8 @@ void ASTReader::diagnoseOdrViolations()
 StaticAssert,
 Field,
 CXXMethod,
+TypeAlias,
+TypeDef,
 Other
   } FirstDiffType = Other,
 SecondDiffType = Other;
@@ -9277,6 +9280,10 @@ void ASTReader::diagnoseOdrViolations()
   return Field;
 case Decl::CXXMethod:
   return CXXMethod;
+case Decl::TypeAlias:
+  return TypeAlias;
+case Decl::Typedef:
+  return TypeDef;
 }
   };
 
@@ -9373,6 +9380,8 @@ void ASTReader::diagnoseOdrViolations()
 MethodNumberParameters,
 MethodParameterType,
 MethodParameterName,
+TypedefName,
+TypedefType,
   };
 
   // These lambdas have the common portions of the ODR diagnostics.  This
@@ -9748,6 +9757,38 @@ void ASTReader::diagnoseOdrViolations()
 
 break;
   }
+  case TypeAlias:
+  case TypeDef: {
+TypedefNameDecl *Fi

r305239 - Revert r301742 which made ExprConstant checking apply to all full-exprs.

2017-06-12 Thread Nick Lewycky via cfe-commits
Author: nicholas
Date: Mon Jun 12 16:59:18 2017
New Revision: 305239

URL: http://llvm.org/viewvc/llvm-project?rev=305239&view=rev
Log:
Revert r301742 which made ExprConstant checking apply to all full-exprs.

This patch also exposed pre-existing bugs in clang, see PR32864 and PR33140#c3 .

Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/OpenMP/distribute_parallel_for_simd_aligned_messages.cpp
cfe/trunk/test/OpenMP/distribute_simd_aligned_messages.cpp
cfe/trunk/test/OpenMP/for_simd_aligned_messages.cpp
cfe/trunk/test/OpenMP/parallel_for_simd_aligned_messages.cpp
cfe/trunk/test/OpenMP/simd_aligned_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_for_simd_aligned_messages.cpp
cfe/trunk/test/OpenMP/target_simd_aligned_messages.cpp

cfe/trunk/test/OpenMP/target_teams_distribute_parallel_for_simd_aligned_messages.cpp
cfe/trunk/test/OpenMP/target_teams_distribute_simd_aligned_messages.cpp
cfe/trunk/test/OpenMP/taskloop_simd_aligned_messages.cpp

cfe/trunk/test/OpenMP/teams_distribute_parallel_for_simd_aligned_messages.cpp
cfe/trunk/test/OpenMP/teams_distribute_simd_aligned_messages.cpp
cfe/trunk/test/Sema/integer-overflow.c

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=305239&r1=305238&r2=305239&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Mon Jun 12 16:59:18 2017
@@ -10273,6 +10273,7 @@ private:
   void CheckFloatComparison(SourceLocation Loc, Expr* LHS, Expr* RHS);
   void CheckImplicitConversions(Expr *E, SourceLocation CC = SourceLocation());
   void CheckBoolLikeConversion(Expr *E, SourceLocation CC);
+  void CheckForIntOverflow(Expr *E);
   void CheckUnsequencedOperations(Expr *E);
 
   /// \brief Perform semantic checks on a completed expression. This will 
either

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=305239&r1=305238&r2=305239&view=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Mon Jun 12 16:59:18 2017
@@ -6226,10 +6226,6 @@ bool RecordExprEvaluator::VisitInitListE
 // the initializer list.
 ImplicitValueInitExpr VIE(HaveInit ? Info.Ctx.IntTy : Field->getType());
 const Expr *Init = HaveInit ? E->getInit(ElementNo++) : &VIE;
-if (Init->isValueDependent()) {
-  Success = false;
-  continue;
-}
 
 // Temporarily override This, in case there's a CXXDefaultInitExpr in here.
 ThisOverrideRAII ThisOverride(*Info.CurrentCall, &This,
@@ -9940,8 +9936,7 @@ static bool EvaluateAsRValue(EvalInfo &I
 }
 
 static bool FastEvaluateAsRValue(const Expr *Exp, Expr::EvalResult &Result,
- const ASTContext &Ctx, bool &IsConst,
- bool IsCheckingForOverflow) {
+ const ASTContext &Ctx, bool &IsConst) {
   // Fast-path evaluations of integer literals, since we sometimes see files
   // containing vast quantities of these.
   if (const IntegerLiteral *L = dyn_cast(Exp)) {
@@ -9962,7 +9957,7 @@ static bool FastEvaluateAsRValue(const E
   // performance problems. Only do so in C++11 for now.
   if (Exp->isRValue() && (Exp->getType()->isArrayType() ||
   Exp->getType()->isRecordType()) &&
-  !Ctx.getLangOpts().CPlusPlus11 && !IsCheckingForOverflow) {
+  !Ctx.getLangOpts().CPlusPlus11) {
 IsConst = false;
 return true;
   }
@@ -9977,7 +9972,7 @@ static bool FastEvaluateAsRValue(const E
 /// will be applied to the result.
 bool Expr::EvaluateAsRValue(EvalResult &Result, const ASTContext &Ctx) const {
   bool IsConst;
-  if (FastEvaluateAsRValue(this, Result, Ctx, IsConst, false))
+  if (FastEvaluateAsRValue(this, Result, Ctx, IsConst))
 return IsConst;
   
   EvalInfo Info(Ctx, Result, EvalInfo::EM_IgnoreSideEffects);
@@ -10102,7 +10097,7 @@ APSInt Expr::EvaluateKnownConstInt(const
 void Expr::EvaluateForOverflow(const ASTContext &Ctx) const {
   bool IsConst;
   EvalResult EvalResult;
-  if (!FastEvaluateAsRValue(this, EvalResult, Ctx, IsConst, true)) {
+  if (!FastEvaluateAsRValue(this, EvalResult, Ctx, IsConst)) {
 EvalInfo Info(Ctx, EvalResult, EvalInfo::EM_EvaluateForOverflow);
 (void)::EvaluateAsRValue(Info, this, EvalResult.Val);
   }

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=305239&r1=305238&r2=305239&view=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Mon Jun 12

[PATCH] D34121: [ubsan] Teach the pointer overflow check that "p - <= p" (PR33430)

2017-06-12 Thread Vedant Kumar via Phabricator via cfe-commits
vsk created this revision.

The pointer overflow check gives false negatives when dealing with
expressions in which an unsigned value is subtracted from a pointer.
This is summarized in PR33430 [1]: ubsan permits the result of the
submission to be greater than "p", but it should not.

To fix the issue, we should track whether or not the pointer expression
is a subtraction. If it is, and the indices are unsigned, we know to
expect "p -  <= p".

I've tested this by running check-{llvm,clang} with a stage2 ubsan-enabled 
build. I've also added some tests to compiler-rt, which I'll upload in a 
separate patch.

[1] https://bugs.llvm.org/show_bug.cgi?id=33430


https://reviews.llvm.org/D34121

Files:
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CGExprScalar.cpp
  lib/CodeGen/CodeGenFunction.h
  test/CodeGen/ubsan-pointer-overflow.m

Index: test/CodeGen/ubsan-pointer-overflow.m
===
--- test/CodeGen/ubsan-pointer-overflow.m
+++ test/CodeGen/ubsan-pointer-overflow.m
@@ -10,16 +10,20 @@
   ++p;
 
   // CHECK: ptrtoint i8* {{.*}} to i64, !nosanitize
-  // CHECK-NEXT: add i64 {{.*}}, -1, !nosanitize
-  // CHECK: select i1 false{{.*}}, !nosanitize
+  // CHECK-NEXT: [[COMPGEP:%.*]] = add i64 {{.*}}, -1, !nosanitize
+  // CHECK: [[NEGVALID:%.*]] = icmp ule i64 [[COMPGEP]], {{.*}}, !nosanitize
+  // CHECK-NOT: select
+  // CHECK: br i1 [[NEGVALID]]{{.*}}, !nosanitize
   // CHECK: call void @__ubsan_handle_pointer_overflow{{.*}}
   --p;
 
+  // CHECK: icmp uge i64
   // CHECK-NOT: select
   // CHECK: call void @__ubsan_handle_pointer_overflow{{.*}}
   p++;
 
-  // CHECK: select
+  // CHECK: icmp ule i64
+  // CHECK-NOT: select
   // CHECK: call void @__ubsan_handle_pointer_overflow{{.*}}
   p--;
 }
@@ -64,7 +68,8 @@
 
   // CHECK: [[OFFSET:%.*]] = sub i64 0, {{.*}}
   // CHECK-NEXT: getelementptr inbounds {{.*}} [[OFFSET]]
-  // CHECK: select
+  // CHECK: icmp ule i64
+  // CHECK-NOT: select
   // CHECK: call void @__ubsan_handle_pointer_overflow{{.*}}
   p - i;
 }
Index: lib/CodeGen/CodeGenFunction.h
===
--- lib/CodeGen/CodeGenFunction.h
+++ lib/CodeGen/CodeGenFunction.h
@@ -3555,9 +3555,12 @@
   /// Same as IRBuilder::CreateInBoundsGEP, but additionally emits a check to
   /// detect undefined behavior when the pointer overflow sanitizer is enabled.
   /// \p SignedIndices indicates whether any of the GEP indices are signed.
+  /// \p IsSubtraction indicates whether the expression used to form the GEP
+  /// is a subtraction.
   llvm::Value *EmitCheckedInBoundsGEP(llvm::Value *Ptr,
   ArrayRef IdxList,
   bool SignedIndices,
+  bool IsSubtraction,
   SourceLocation Loc,
   const Twine &Name = "");
 
Index: lib/CodeGen/CGExprScalar.cpp
===
--- lib/CodeGen/CGExprScalar.cpp
+++ lib/CodeGen/CGExprScalar.cpp
@@ -1851,7 +1851,6 @@
   llvm::Value *input;
 
   int amount = (isInc ? 1 : -1);
-  bool signedIndex = !isInc;
 
   if (const AtomicType *atomicTy = type->getAs()) {
 type = atomicTy->getValueType();
@@ -1941,8 +1940,9 @@
   if (CGF.getLangOpts().isSignedOverflowDefined())
 value = Builder.CreateGEP(value, numElts, "vla.inc");
   else
-value = CGF.EmitCheckedInBoundsGEP(value, numElts, signedIndex,
-   E->getExprLoc(), "vla.inc");
+value = CGF.EmitCheckedInBoundsGEP(
+value, numElts, /*SignedIndices=*/false, /*IsSubtraction=*/!isInc,
+E->getExprLoc(), "vla.inc");
 
 // Arithmetic on function pointers (!) is just +-1.
 } else if (type->isFunctionType()) {
@@ -1952,7 +1952,8 @@
   if (CGF.getLangOpts().isSignedOverflowDefined())
 value = Builder.CreateGEP(value, amt, "incdec.funcptr");
   else
-value = CGF.EmitCheckedInBoundsGEP(value, amt, signedIndex,
+value = CGF.EmitCheckedInBoundsGEP(value, amt, /*SignedIndices=*/false,
+   /*IsSubtraction=*/!isInc,
E->getExprLoc(), "incdec.funcptr");
   value = Builder.CreateBitCast(value, input->getType());
 
@@ -1962,7 +1963,8 @@
   if (CGF.getLangOpts().isSignedOverflowDefined())
 value = Builder.CreateGEP(value, amt, "incdec.ptr");
   else
-value = CGF.EmitCheckedInBoundsGEP(value, amt, signedIndex,
+value = CGF.EmitCheckedInBoundsGEP(value, amt, /*SignedIndices=*/false,
+   /*IsSubtraction=*/!isInc,
E->getExprLoc(), "incdec.ptr");
 }
 
@@ -2044,8 +2046,9 @@
 if (CGF.getLangOpts().isSignedOverflowDefined())
   value = Builder.CreateGEP(value, sizeValue, "incdec.objptr");

[PATCH] D34121: [ubsan] Teach the pointer overflow check that "p - <= p" (PR33430)

2017-06-12 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

Looks okay, but I haven't been reviewing this series of patches closely, so I 
could be missing something.




Comment at: lib/CodeGen/CGExprScalar.cpp:3974
 ValidGEP = Builder.CreateAnd(PosOrZeroValid, NoOffsetOverflow);
+  } else if (!SignedIndices && IsSubtraction) {
+auto *NegOrZeroValid = Builder.CreateICmpULE(ComputedGEP, IntPtr);

Please make this an "else" rather than an "else if" (you can assert the inside 
the else body if it's helpful).


https://reviews.llvm.org/D34121



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


[PATCH] D34121: [ubsan] Teach the pointer overflow check that "p - <= p" (PR33430)

2017-06-12 Thread Vedant Kumar via Phabricator via cfe-commits
vsk updated this revision to Diff 102261.
vsk marked an inline comment as done.
vsk edited the summary of this revision.
vsk added a comment.

Thanks for the review! I'll wait for another 'lgtm'.


https://reviews.llvm.org/D34121

Files:
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CGExprScalar.cpp
  lib/CodeGen/CodeGenFunction.h
  test/CodeGen/ubsan-pointer-overflow.m

Index: test/CodeGen/ubsan-pointer-overflow.m
===
--- test/CodeGen/ubsan-pointer-overflow.m
+++ test/CodeGen/ubsan-pointer-overflow.m
@@ -10,16 +10,20 @@
   ++p;
 
   // CHECK: ptrtoint i8* {{.*}} to i64, !nosanitize
-  // CHECK-NEXT: add i64 {{.*}}, -1, !nosanitize
-  // CHECK: select i1 false{{.*}}, !nosanitize
+  // CHECK-NEXT: [[COMPGEP:%.*]] = add i64 {{.*}}, -1, !nosanitize
+  // CHECK: [[NEGVALID:%.*]] = icmp ule i64 [[COMPGEP]], {{.*}}, !nosanitize
+  // CHECK-NOT: select
+  // CHECK: br i1 [[NEGVALID]]{{.*}}, !nosanitize
   // CHECK: call void @__ubsan_handle_pointer_overflow{{.*}}
   --p;
 
+  // CHECK: icmp uge i64
   // CHECK-NOT: select
   // CHECK: call void @__ubsan_handle_pointer_overflow{{.*}}
   p++;
 
-  // CHECK: select
+  // CHECK: icmp ule i64
+  // CHECK-NOT: select
   // CHECK: call void @__ubsan_handle_pointer_overflow{{.*}}
   p--;
 }
@@ -64,7 +68,8 @@
 
   // CHECK: [[OFFSET:%.*]] = sub i64 0, {{.*}}
   // CHECK-NEXT: getelementptr inbounds {{.*}} [[OFFSET]]
-  // CHECK: select
+  // CHECK: icmp ule i64
+  // CHECK-NOT: select
   // CHECK: call void @__ubsan_handle_pointer_overflow{{.*}}
   p - i;
 }
Index: lib/CodeGen/CodeGenFunction.h
===
--- lib/CodeGen/CodeGenFunction.h
+++ lib/CodeGen/CodeGenFunction.h
@@ -3555,9 +3555,12 @@
   /// Same as IRBuilder::CreateInBoundsGEP, but additionally emits a check to
   /// detect undefined behavior when the pointer overflow sanitizer is enabled.
   /// \p SignedIndices indicates whether any of the GEP indices are signed.
+  /// \p IsSubtraction indicates whether the expression used to form the GEP
+  /// is a subtraction.
   llvm::Value *EmitCheckedInBoundsGEP(llvm::Value *Ptr,
   ArrayRef IdxList,
   bool SignedIndices,
+  bool IsSubtraction,
   SourceLocation Loc,
   const Twine &Name = "");
 
Index: lib/CodeGen/CGExprScalar.cpp
===
--- lib/CodeGen/CGExprScalar.cpp
+++ lib/CodeGen/CGExprScalar.cpp
@@ -1851,7 +1851,6 @@
   llvm::Value *input;
 
   int amount = (isInc ? 1 : -1);
-  bool signedIndex = !isInc;
 
   if (const AtomicType *atomicTy = type->getAs()) {
 type = atomicTy->getValueType();
@@ -1941,8 +1940,9 @@
   if (CGF.getLangOpts().isSignedOverflowDefined())
 value = Builder.CreateGEP(value, numElts, "vla.inc");
   else
-value = CGF.EmitCheckedInBoundsGEP(value, numElts, signedIndex,
-   E->getExprLoc(), "vla.inc");
+value = CGF.EmitCheckedInBoundsGEP(
+value, numElts, /*SignedIndices=*/false, /*IsSubtraction=*/!isInc,
+E->getExprLoc(), "vla.inc");
 
 // Arithmetic on function pointers (!) is just +-1.
 } else if (type->isFunctionType()) {
@@ -1952,7 +1952,8 @@
   if (CGF.getLangOpts().isSignedOverflowDefined())
 value = Builder.CreateGEP(value, amt, "incdec.funcptr");
   else
-value = CGF.EmitCheckedInBoundsGEP(value, amt, signedIndex,
+value = CGF.EmitCheckedInBoundsGEP(value, amt, /*SignedIndices=*/false,
+   /*IsSubtraction=*/!isInc,
E->getExprLoc(), "incdec.funcptr");
   value = Builder.CreateBitCast(value, input->getType());
 
@@ -1962,7 +1963,8 @@
   if (CGF.getLangOpts().isSignedOverflowDefined())
 value = Builder.CreateGEP(value, amt, "incdec.ptr");
   else
-value = CGF.EmitCheckedInBoundsGEP(value, amt, signedIndex,
+value = CGF.EmitCheckedInBoundsGEP(value, amt, /*SignedIndices=*/false,
+   /*IsSubtraction=*/!isInc,
E->getExprLoc(), "incdec.ptr");
 }
 
@@ -2044,8 +2046,9 @@
 if (CGF.getLangOpts().isSignedOverflowDefined())
   value = Builder.CreateGEP(value, sizeValue, "incdec.objptr");
 else
-  value = CGF.EmitCheckedInBoundsGEP(value, sizeValue, signedIndex,
- E->getExprLoc(), "incdec.objptr");
+  value = CGF.EmitCheckedInBoundsGEP(
+  value, sizeValue, /*SignedIndices=*/false, /*IsSubtraction=*/!isInc,
+  E->getExprLoc(), "incdec.objptr");
 value = Builder.CreateBitCast(value, input->getType());
   }
 
@@ -2663,7 +2666,6 @@
   }
 
   bool isSigned = indexOperand->getType(

[PATCH] D33305: [ubsan] Add a check for pointer overflow UB

2017-06-12 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a comment.

@sberg I agree with @regehr's analysis, and do think that this is a real 
overflow. Once https://reviews.llvm.org/D34121 lands, we will report this issue 
in a better way:

  runtime error: addition of unsigned offset to 0x7fff59dfe990 overflowed to 
0x7fff59dfe980


Repository:
  rL LLVM

https://reviews.llvm.org/D33305



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


[PATCH] D32146: PR32476: __nop_locale_mgmt.h not needed with newlib 2.5+

2017-06-12 Thread Walter Lee via Phabricator via cfe-commits
waltl commandeered this revision.
waltl added a reviewer: bcraig.
waltl added a comment.

Thanks for submitting the patch -- I will make the necessary revision and test 
it.


https://reviews.llvm.org/D32146



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


[PATCH] D32146: PR32476: __nop_locale_mgmt.h not needed with newlib 2.5+

2017-06-12 Thread Walter Lee via Phabricator via cfe-commits
waltl updated this revision to Diff 102265.
waltl added a comment.

PR32476: __nop_locale_mgmt.h not needed with newlib 2.5+

Newlib 2.5 added the locale management functions, so it should not
include __nop_local_mgmt.h.  This change adds proper guard around that
include statement.

For newlib 2.4, some releases contain these functions and some don't,
and they all have the same version numbers.  This patch will work
properly with the initial "2.4.0" release which does not include these
functions and require __nop_local_mgmt.h.

I've tested this against newlib 2.2 and 2.5, and also sanity check
against other different version numbers.


https://reviews.llvm.org/D32146

Files:
  include/support/newlib/xlocale.h


Index: include/support/newlib/xlocale.h
===
--- include/support/newlib/xlocale.h
+++ include/support/newlib/xlocale.h
@@ -16,7 +16,10 @@
 #include 
 #include 
 #include 
+#if !defined(__NEWLIB__) || __NEWLIB__ < 2 || \
+__NEWLIB__ == 2 && __NEWLIB_MINOR__ < 5
 #include 
+#endif
 #include 
 #include 
 


Index: include/support/newlib/xlocale.h
===
--- include/support/newlib/xlocale.h
+++ include/support/newlib/xlocale.h
@@ -16,7 +16,10 @@
 #include 
 #include 
 #include 
+#if !defined(__NEWLIB__) || __NEWLIB__ < 2 || \
+__NEWLIB__ == 2 && __NEWLIB_MINOR__ < 5
 #include 
+#endif
 #include 
 #include 
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D32613: [Driver] Update Fuchsia driver path handling

2017-06-12 Thread Petr Hosek via Phabricator via cfe-commits
phosek updated this revision to Diff 102271.

Repository:
  rL LLVM

https://reviews.llvm.org/D32613

Files:
  lib/Driver/ToolChains/Fuchsia.cpp
  lib/Driver/ToolChains/Fuchsia.h
  test/Driver/fuchsia.cpp

Index: test/Driver/fuchsia.cpp
===
--- test/Driver/fuchsia.cpp
+++ test/Driver/fuchsia.cpp
@@ -3,7 +3,7 @@
 // CHECK: {{.*}}clang{{.*}}" "-cc1"
 // CHECK: "-fuse-init-array"
 // CHECK: "-isysroot" "[[SYSROOT:[^"]+]]"
-// CHECK: "-internal-isystem" "[[SYSROOT]]{{/|}}include{{/|}}c++{{/|}}v1"
+// CHECK: "-internal-isystem" "{{.*[/\\]}}x86_64-unknown-fuchsia{{/|}}include{{/|}}c++{{/|}}v1"
 // CHECK: "-internal-externc-isystem" "[[SYSROOT]]{{/|}}include"
 // CHECK: {{.*}}lld{{.*}}" "-flavor" "gnu"
 // CHECK: "--sysroot=[[SYSROOT]]"
Index: lib/Driver/ToolChains/Fuchsia.h
===
--- lib/Driver/ToolChains/Fuchsia.h
+++ lib/Driver/ToolChains/Fuchsia.h
@@ -35,14 +35,22 @@
 
 namespace toolchains {
 
-class LLVM_LIBRARY_VISIBILITY Fuchsia : public Generic_ELF {
+class LLVM_LIBRARY_VISIBILITY Fuchsia : public ToolChain {
 public:
   Fuchsia(const Driver &D, const llvm::Triple &Triple,
   const llvm::opt::ArgList &Args);
 
-  bool isPIEDefault() const override { return true; }
   bool HasNativeLLVMSupport() const override { return true; }
   bool IsIntegratedAssemblerDefault() const override { return true; }
+  RuntimeLibType GetDefaultRuntimeLibType() const override {
+return ToolChain::RLT_CompilerRT;
+  }
+  CXXStdlibType GetDefaultCXXStdlibType() const override {
+return ToolChain::CST_Libcxx;
+  }
+  bool isPICDefault() const override { return false; }
+  bool isPIEDefault() const override { return true; }
+  bool isPICDefaultForced() const override { return false; }
   llvm::DebuggerKind getDefaultDebuggerTuning() const override {
 return llvm::DebuggerKind::GDB;
   }
@@ -59,16 +67,17 @@
   void
   AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
 llvm::opt::ArgStringList &CC1Args) const override;
-  std::string findLibCxxIncludePath() const override;
+  void
+  AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
+   llvm::opt::ArgStringList &CC1Args) const override;
   void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs) const override;
 
   const char *getDefaultLinker() const override {
 return "lld";
   }
 
 protected:
-  Tool *buildAssembler() const override;
   Tool *buildLinker() const override;
 };
 
Index: lib/Driver/ToolChains/Fuchsia.cpp
===
--- lib/Driver/ToolChains/Fuchsia.cpp
+++ lib/Driver/ToolChains/Fuchsia.cpp
@@ -131,16 +131,30 @@
 
 /// Fuchsia - Fuchsia tool chain which can call as(1) and ld(1) directly.
 
-Fuchsia::Fuchsia(const Driver &D, const llvm::Triple &Triple,
- const ArgList &Args)
-: Generic_ELF(D, Triple, Args) {
-
-  getFilePaths().push_back(D.SysRoot + "/lib");
-  getFilePaths().push_back(D.ResourceDir + "/lib/fuchsia");
+static std::string getTargetDir(const Driver &D,
+llvm::Triple TargetTriple) {
+  SmallString<128> P(llvm::sys::path::parent_path(D.Dir));
+  TargetTriple.setVendor(llvm::Triple::UnknownVendor);
+  llvm::sys::path::append(P, "lib", TargetTriple.normalize());
+  return P.str();
 }
 
-Tool *Fuchsia::buildAssembler() const {
-  return new tools::gnutools::Assembler(*this);
+Fuchsia::Fuchsia(const Driver &D, const llvm::Triple &Triple,
+ const ArgList &Args)
+: ToolChain(D, Triple, Args) {
+  getProgramPaths().push_back(getDriver().getInstalledDir());
+  if (getDriver().getInstalledDir() != D.Dir)
+getProgramPaths().push_back(D.Dir);
+
+  SmallString<128> P(getTargetDir(D, getTriple()));
+  llvm::sys::path::append(P, "lib");
+  getFilePaths().push_back(P.str());
+
+  if (!D.SysRoot.empty()) {
+SmallString<128> P(D.SysRoot);
+llvm::sys::path::append(P, "lib");
+getFilePaths().push_back(P.str());
+  }
 }
 
 Tool *Fuchsia::buildLinker() const {
@@ -207,19 +221,44 @@
 return;
   }
 
-  addExternCSystemInclude(DriverArgs, CC1Args, D.SysRoot + "/include");
+  if (!D.SysRoot.empty()) {
+SmallString<128> P(D.SysRoot);
+llvm::sys::path::append(P, "include");
+addExternCSystemInclude(DriverArgs, CC1Args, P.str());
+  }
 }
 
-std::string Fuchsia::findLibCxxIncludePath() const {
-  return getDriver().SysRoot + "/include/c++/v1";
+void Fuchsia::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
+   ArgStringList &CC1Args) const {
+  if (DriverArgs.hasArg(options::OPT_nostdlibinc) ||
+  DriverArgs.hasArg(options::OPT_nostdincxx))
+return;
+
+  switch (GetCXXStdlibType(DriverArgs)) {
+  case ToolChain::CST_Libcxx: {
+SmallString<128> 

[PATCH] D34021: [coroutines] Fix co_await for range statement

2017-06-12 Thread Gor Nishanov via Phabricator via cfe-commits
GorNishanov accepted this revision.
GorNishanov added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D34021



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


[PATCH] D34133: Cold attribute on function decls are lost. Fix the problem

2017-06-12 Thread David Li via Phabricator via cfe-commits
davidxl created this revision.
Herald added a subscriber: sanjoy.

LLVM static branch prediction depends on cold attribute to annotate branch 
probability. This is  currently not possible for cold function decls as the 
information is dropped by FE.

This patch attaches the attributes to the callsite as noReturn. Another way is 
to pass the attribute to the function decl.

Also need suggestions on how to add a clang test case.


https://reviews.llvm.org/D34133

Files:
  lib/CodeGen/CGCall.cpp


Index: lib/CodeGen/CGCall.cpp
===
--- lib/CodeGen/CGCall.cpp
+++ lib/CodeGen/CGCall.cpp
@@ -1795,6 +1795,8 @@
   FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
 if (TargetDecl->hasAttr())
   FuncAttrs.addAttribute(llvm::Attribute::NoReturn);
+if (TargetDecl->hasAttr())
+  FuncAttrs.addAttribute(llvm::Attribute::Cold);
 if (TargetDecl->hasAttr())
   FuncAttrs.addAttribute(llvm::Attribute::NoDuplicate);
 if (TargetDecl->hasAttr())


Index: lib/CodeGen/CGCall.cpp
===
--- lib/CodeGen/CGCall.cpp
+++ lib/CodeGen/CGCall.cpp
@@ -1795,6 +1795,8 @@
   FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
 if (TargetDecl->hasAttr())
   FuncAttrs.addAttribute(llvm::Attribute::NoReturn);
+if (TargetDecl->hasAttr())
+  FuncAttrs.addAttribute(llvm::Attribute::Cold);
 if (TargetDecl->hasAttr())
   FuncAttrs.addAttribute(llvm::Attribute::NoDuplicate);
 if (TargetDecl->hasAttr())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] r305268 - Add a test with an empty input range - should do nothing

2017-06-12 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Mon Jun 12 21:28:40 2017
New Revision: 305268

URL: http://llvm.org/viewvc/llvm-project?rev=305268&view=rev
Log:
Add a test with an empty input range - should do nothing

Modified:

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

Modified: 
libcxx/trunk/test/std/numerics/numeric.ops/transform.exclusive.scan/transform_exclusive_scan_iter_iter_iter_init_bop_uop.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/numerics/numeric.ops/transform.exclusive.scan/transform_exclusive_scan_iter_iter_iter_init_bop_uop.pass.cpp?rev=305268&r1=305267&r2=305268&view=diff
==
--- 
libcxx/trunk/test/std/numerics/numeric.ops/transform.exclusive.scan/transform_exclusive_scan_iter_iter_iter_init_bop_uop.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/numerics/numeric.ops/transform.exclusive.scan/transform_exclusive_scan_iter_iter_iter_init_bop_uop.pass.cpp
 Mon Jun 12 21:28:40 2017
@@ -122,6 +122,12 @@ void basic_tests()
 assert(v[i] == 40 + triangle(i));
 }
 
+{
+std::vector v, res;
+std::transform_exclusive_scan(v.begin(), v.end(), std::back_inserter(res), 
40, std::plus<>(), identity<>());
+assert(res.empty());
+}
+
 //  Make sure that the calculations are done using the init typedef
 {
 std::vector v(10);


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


r305269 - [docs] Add some ubsan changes to the release notes

2017-06-12 Thread Vedant Kumar via cfe-commits
Author: vedantk
Date: Mon Jun 12 21:52:31 2017
New Revision: 305269

URL: http://llvm.org/viewvc/llvm-project?rev=305269&view=rev
Log:
[docs] Add some ubsan changes to the release notes

Modified:
cfe/trunk/docs/ReleaseNotes.rst

Modified: cfe/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ReleaseNotes.rst?rev=305269&r1=305268&r2=305269&view=diff
==
--- cfe/trunk/docs/ReleaseNotes.rst (original)
+++ cfe/trunk/docs/ReleaseNotes.rst Mon Jun 12 21:52:31 2017
@@ -187,6 +187,31 @@ Static Analyzer
 
 ...
 
+Undefined Behavior Sanitizer (UBSan)
+
+
+- The Undefined Behavior Sanitizer has a new check for pointer overflow. This
+  check is on by default. The flag to control this functionality is
+  -fsanitize=pointer-overflow.
+
+  Pointer overflow is an indicator of undefined behavior: when a pointer
+  indexing expression wraps around the address space, or produces other
+  unexpected results, its result may not point to a valid object.
+
+- UBSan has several new checks which detect violations of nullability
+  annotations. These checks are off by default. The flag to control this group
+  of checks is -fsanitize=nullability. The checks can be individially enabled
+  by -fsanitize=nullability-arg (which checks calls),
+  -fsanitize=nullability-assign (which checks assignments), and
+  -fsanitize=nullability-return (which checks return statements).
+
+- UBSan can now detect invalid loads from bitfields and from ObjC BOOLs.
+
+- UBSan can now avoid emitting unnecessary type checks in C++ class methods and
+  in several other cases where the result is known at compile-time. UBSan can
+  also avoid emitting unnecessary overflow checks in arithmetic expressions
+  with promoted integer operands.
+
 Core Analysis Improvements
 ==
 


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


[PATCH] D16971: [Sema] PR26077 Fixed crash when partial specialization is missing required parameters

2017-06-12 Thread don hinton via Phabricator via cfe-commits
hintonda updated this revision to Diff 102292.
hintonda added a comment.

Rebase, fix test, and add FIXME note.


https://reviews.llvm.org/D16971

Files:
  lib/Sema/SemaTemplate.cpp
  test/SemaTemplate/partial-spec-fully-specified.cpp


Index: test/SemaTemplate/partial-spec-fully-specified.cpp
===
--- /dev/null
+++ test/SemaTemplate/partial-spec-fully-specified.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+
+template 
+struct Base{};
+
+template 
+class Test {};
+
+template 
+class Test : Base { // expected-error{{partial specialization 
of 'Test' does not use any of its template parameters}}
+  Test() {}
+};
Index: lib/Sema/SemaTemplate.cpp
===
--- lib/Sema/SemaTemplate.cpp
+++ lib/Sema/SemaTemplate.cpp
@@ -3418,7 +3418,9 @@
 InstantiationDependent)) {
   Diag(TemplateNameLoc, diag::err_partial_spec_fully_specialized)
   << VarTemplate->getDeclName();
-  IsPartialSpecialization = false;
+  // FIXME: Can this ever get triggered?  If so, we need test.  If not,
+  // should this if be removed?
+  return true;
 }
 
 if (isSameAsPrimaryTemplate(VarTemplate->getTemplateParameters(),
@@ -7276,7 +7278,7 @@
 TemplateArgs.arguments(), InstantiationDependent)) {
   Diag(TemplateNameLoc, diag::err_partial_spec_fully_specialized)
 << ClassTemplate->getDeclName();
-  isPartialSpecialization = false;
+  return true;
 }
   }
 


Index: test/SemaTemplate/partial-spec-fully-specified.cpp
===
--- /dev/null
+++ test/SemaTemplate/partial-spec-fully-specified.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+
+template 
+struct Base{};
+
+template 
+class Test {};
+
+template 
+class Test : Base { // expected-error{{partial specialization of 'Test' does not use any of its template parameters}}
+  Test() {}
+};
Index: lib/Sema/SemaTemplate.cpp
===
--- lib/Sema/SemaTemplate.cpp
+++ lib/Sema/SemaTemplate.cpp
@@ -3418,7 +3418,9 @@
 InstantiationDependent)) {
   Diag(TemplateNameLoc, diag::err_partial_spec_fully_specialized)
   << VarTemplate->getDeclName();
-  IsPartialSpecialization = false;
+  // FIXME: Can this ever get triggered?  If so, we need test.  If not,
+  // should this if be removed?
+  return true;
 }
 
 if (isSameAsPrimaryTemplate(VarTemplate->getTemplateParameters(),
@@ -7276,7 +7278,7 @@
 TemplateArgs.arguments(), InstantiationDependent)) {
   Diag(TemplateNameLoc, diag::err_partial_spec_fully_specialized)
 << ClassTemplate->getDeclName();
-  isPartialSpecialization = false;
+  return true;
 }
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34052: [XRay][clang] Support capturing the implicit `this` argument to C++ class member functions

2017-06-12 Thread Dean Michael Berris via Phabricator via cfe-commits
dberris added a reviewer: dblaikie.
dberris added a subscriber: dblaikie.
dberris added a comment.

@dblaikie -- do you have time to have a look?


https://reviews.llvm.org/D34052



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


Re: r305239 - Revert r301742 which made ExprConstant checking apply to all full-exprs.

2017-06-12 Thread NAKAMURA Takumi via cfe-commits
It triggered a test failure for targeting i686 (seems also for arm)
See also; http://bb.pgr.jp/builders/test-clang-i686-linux-RA/builds/3566

On Tue, Jun 13, 2017 at 6:59 AM Nick Lewycky via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: nicholas
> Date: Mon Jun 12 16:59:18 2017
> New Revision: 305239
>
> URL: http://llvm.org/viewvc/llvm-project?rev=305239&view=rev
> Log:
> Revert r301742 which made ExprConstant checking apply to all full-exprs.
>
> This patch also exposed pre-existing bugs in clang, see PR32864 and
> PR33140#c3 .
>
> Modified:
> cfe/trunk/include/clang/Sema/Sema.h
> cfe/trunk/lib/AST/ExprConstant.cpp
> cfe/trunk/lib/Sema/SemaChecking.cpp
> cfe/trunk/test/OpenMP/distribute_parallel_for_simd_aligned_messages.cpp
> cfe/trunk/test/OpenMP/distribute_simd_aligned_messages.cpp
> cfe/trunk/test/OpenMP/for_simd_aligned_messages.cpp
> cfe/trunk/test/OpenMP/parallel_for_simd_aligned_messages.cpp
> cfe/trunk/test/OpenMP/simd_aligned_messages.cpp
> cfe/trunk/test/OpenMP/target_parallel_for_simd_aligned_messages.cpp
> cfe/trunk/test/OpenMP/target_simd_aligned_messages.cpp
>
> cfe/trunk/test/OpenMP/target_teams_distribute_parallel_for_simd_aligned_messages.cpp
> cfe/trunk/test/OpenMP/target_teams_distribute_simd_aligned_messages.cpp
> cfe/trunk/test/OpenMP/taskloop_simd_aligned_messages.cpp
>
> cfe/trunk/test/OpenMP/teams_distribute_parallel_for_simd_aligned_messages.cpp
> cfe/trunk/test/OpenMP/teams_distribute_simd_aligned_messages.cpp
> cfe/trunk/test/Sema/integer-overflow.c
>
> Modified: cfe/trunk/include/clang/Sema/Sema.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=305239&r1=305238&r2=305239&view=diff
>
> ==
> --- cfe/trunk/include/clang/Sema/Sema.h (original)
> +++ cfe/trunk/include/clang/Sema/Sema.h Mon Jun 12 16:59:18 2017
> @@ -10273,6 +10273,7 @@ private:
>void CheckFloatComparison(SourceLocation Loc, Expr* LHS, Expr* RHS);
>void CheckImplicitConversions(Expr *E, SourceLocation CC =
> SourceLocation());
>void CheckBoolLikeConversion(Expr *E, SourceLocation CC);
> +  void CheckForIntOverflow(Expr *E);
>void CheckUnsequencedOperations(Expr *E);
>
>/// \brief Perform semantic checks on a completed expression. This will
> either
>
> Modified: cfe/trunk/lib/AST/ExprConstant.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=305239&r1=305238&r2=305239&view=diff
>
> ==
> --- cfe/trunk/lib/AST/ExprConstant.cpp (original)
> +++ cfe/trunk/lib/AST/ExprConstant.cpp Mon Jun 12 16:59:18 2017
> @@ -6226,10 +6226,6 @@ bool RecordExprEvaluator::VisitInitListE
>  // the initializer list.
>  ImplicitValueInitExpr VIE(HaveInit ? Info.Ctx.IntTy :
> Field->getType());
>  const Expr *Init = HaveInit ? E->getInit(ElementNo++) : &VIE;
> -if (Init->isValueDependent()) {
> -  Success = false;
> -  continue;
> -}
>
>  // Temporarily override This, in case there's a CXXDefaultInitExpr in
> here.
>  ThisOverrideRAII ThisOverride(*Info.CurrentCall, &This,
> @@ -9940,8 +9936,7 @@ static bool EvaluateAsRValue(EvalInfo &I
>  }
>
>  static bool FastEvaluateAsRValue(const Expr *Exp, Expr::EvalResult
> &Result,
> - const ASTContext &Ctx, bool &IsConst,
> - bool IsCheckingForOverflow) {
> + const ASTContext &Ctx, bool &IsConst) {
>// Fast-path evaluations of integer literals, since we sometimes see
> files
>// containing vast quantities of these.
>if (const IntegerLiteral *L = dyn_cast(Exp)) {
> @@ -9962,7 +9957,7 @@ static bool FastEvaluateAsRValue(const E
>// performance problems. Only do so in C++11 for now.
>if (Exp->isRValue() && (Exp->getType()->isArrayType() ||
>Exp->getType()->isRecordType()) &&
> -  !Ctx.getLangOpts().CPlusPlus11 && !IsCheckingForOverflow) {
> +  !Ctx.getLangOpts().CPlusPlus11) {
>  IsConst = false;
>  return true;
>}
> @@ -9977,7 +9972,7 @@ static bool FastEvaluateAsRValue(const E
>  /// will be applied to the result.
>  bool Expr::EvaluateAsRValue(EvalResult &Result, const ASTContext &Ctx)
> const {
>bool IsConst;
> -  if (FastEvaluateAsRValue(this, Result, Ctx, IsConst, false))
> +  if (FastEvaluateAsRValue(this, Result, Ctx, IsConst))
>  return IsConst;
>
>EvalInfo Info(Ctx, Result, EvalInfo::EM_IgnoreSideEffects);
> @@ -10102,7 +10097,7 @@ APSInt Expr::EvaluateKnownConstInt(const
>  void Expr::EvaluateForOverflow(const ASTContext &Ctx) const {
>bool IsConst;
>EvalResult EvalResult;
> -  if (!FastEvaluateAsRValue(this, EvalResult, Ctx, IsConst, true)) {
> +  if (!FastEvaluateAsRValue(this, EvalResult, Ctx, IsConst)) {
>  EvalInfo Info(Ctx, EvalResult, EvalInfo::EM_Evalu

[PATCH] D34052: [XRay][clang] Support capturing the implicit `this` argument to C++ class member functions

2017-06-12 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

I take it there's already handling for these attributes on non-member functions?

There's probably a reason this code can't be wherever that code is & subtract 
one from the index? (reducing code duplication by having all the error 
handling, etc, in one place/once)


https://reviews.llvm.org/D34052



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