From owner-svn-src-all@freebsd.org Tue Jan 24 19:18:07 2017 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 3A622CBF56C; Tue, 24 Jan 2017 19:18:07 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 04390A9F; Tue, 24 Jan 2017 19:18:06 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v0OJI62v072303; Tue, 24 Jan 2017 19:18:06 GMT (envelope-from dim@FreeBSD.org) Received: (from dim@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v0OJI4q2072290; Tue, 24 Jan 2017 19:18:04 GMT (envelope-from dim@FreeBSD.org) Message-Id: <201701241918.v0OJI4q2072290@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: dim set sender to dim@FreeBSD.org using -f From: Dimitry Andric Date: Tue, 24 Jan 2017 19:18:04 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-vendor@freebsd.org Subject: svn commit: r312706 - in vendor/clang/dist: docs include/clang/Basic lib/AST lib/CodeGen lib/Lex lib/Sema test/CodeGenCXX test/Lexer test/Sema test/SemaCXX X-SVN-Group: vendor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Jan 2017 19:18:07 -0000 Author: dim Date: Tue Jan 24 19:18:04 2017 New Revision: 312706 URL: https://svnweb.freebsd.org/changeset/base/312706 Log: Vendor import of clang release_40 branch r292951: https://llvm.org/svn/llvm-project/cfe/branches/release_40@292951 Added: vendor/clang/dist/test/Sema/PR28181.c (contents, props changed) vendor/clang/dist/test/SemaCXX/cxx11-default-member-initializers.cpp (contents, props changed) Modified: vendor/clang/dist/docs/LanguageExtensions.rst vendor/clang/dist/include/clang/Basic/Builtins.def vendor/clang/dist/lib/AST/ExprConstant.cpp vendor/clang/dist/lib/CodeGen/CGBuiltin.cpp vendor/clang/dist/lib/Lex/PPMacroExpansion.cpp vendor/clang/dist/lib/Sema/SemaDeclCXX.cpp vendor/clang/dist/lib/Sema/SemaExpr.cpp vendor/clang/dist/test/CodeGenCXX/builtins.cpp vendor/clang/dist/test/Lexer/has_feature_cxx0x.cpp vendor/clang/dist/test/SemaCXX/constexpr-string.cpp Modified: vendor/clang/dist/docs/LanguageExtensions.rst ============================================================================== --- vendor/clang/dist/docs/LanguageExtensions.rst Tue Jan 24 19:17:58 2017 (r312705) +++ vendor/clang/dist/docs/LanguageExtensions.rst Tue Jan 24 19:18:04 2017 (r312706) @@ -1776,6 +1776,46 @@ numeric primitives such as frexp. See `L `_ for more information on the semantics. +String builtins +--------------- + +Clang provides constant expression evaluation support for builtins forms of +the following functions from the C standard library ```` header: + +* ``memchr`` +* ``memcmp`` +* ``strchr`` +* ``strcmp`` +* ``strlen`` +* ``strncmp`` +* ``wcschr`` +* ``wcscmp`` +* ``wcslen`` +* ``wcsncmp`` +* ``wmemchr`` +* ``wmemcmp`` + +In each case, the builtin form has the name of the C library function prefixed +by ``__builtin_``. Example: + +.. code-block:: c + + void *p = __builtin_memchr("foobar", 'b', 5); + +In addition to the above, one further builtin is provided: + +.. code-block:: c + + char *__builtin_char_memchr(const char *haystack, int needle, size_t size); + +``__builtin_char_memchr(a, b, c)`` is identical to +``(char*)__builtin_memchr(a, b, c)`` except that its use is permitted within +constant expressions in C++11 onwards (where a cast from ``void*`` to ``char*`` +is disallowed in general). + +Support for constant expression evaluation for the above builtins be detected +with ``__has_feature(cxx_constexpr_string_builtins)``. + .. _langext-__c11_atomic: __c11_atomic builtins Modified: vendor/clang/dist/include/clang/Basic/Builtins.def ============================================================================== --- vendor/clang/dist/include/clang/Basic/Builtins.def Tue Jan 24 19:17:58 2017 (r312705) +++ vendor/clang/dist/include/clang/Basic/Builtins.def Tue Jan 24 19:18:04 2017 (r312706) @@ -1339,6 +1339,7 @@ BUILTIN(__builtin_smulll_overflow, "bSLL BUILTIN(__builtin_addressof, "v*v&", "nct") BUILTIN(__builtin_operator_new, "v*z", "c") BUILTIN(__builtin_operator_delete, "vv*", "n") +BUILTIN(__builtin_char_memchr, "c*cC*iz", "n") // Safestack builtins BUILTIN(__builtin___get_unsafe_stack_start, "v*", "Fn") Modified: vendor/clang/dist/lib/AST/ExprConstant.cpp ============================================================================== --- vendor/clang/dist/lib/AST/ExprConstant.cpp Tue Jan 24 19:17:58 2017 (r312705) +++ vendor/clang/dist/lib/AST/ExprConstant.cpp Tue Jan 24 19:18:04 2017 (r312706) @@ -5683,6 +5683,7 @@ bool PointerExprEvaluator::VisitBuiltinC case Builtin::BI__builtin_strchr: case Builtin::BI__builtin_wcschr: case Builtin::BI__builtin_memchr: + case Builtin::BI__builtin_char_memchr: case Builtin::BI__builtin_wmemchr: { if (!Visit(E->getArg(0))) return false; @@ -5720,6 +5721,7 @@ bool PointerExprEvaluator::VisitBuiltinC // Fall through. case Builtin::BImemchr: case Builtin::BI__builtin_memchr: + case Builtin::BI__builtin_char_memchr: // memchr compares by converting both sides to unsigned char. That's also // correct for strchr if we get this far (to cope with plain char being // unsigned in the strchr case). Modified: vendor/clang/dist/lib/CodeGen/CGBuiltin.cpp ============================================================================== --- vendor/clang/dist/lib/CodeGen/CGBuiltin.cpp Tue Jan 24 19:17:58 2017 (r312705) +++ vendor/clang/dist/lib/CodeGen/CGBuiltin.cpp Tue Jan 24 19:18:04 2017 (r312706) @@ -1189,6 +1189,10 @@ RValue CodeGenFunction::EmitBuiltinExpr( return RValue::get(Dest.getPointer()); } + case Builtin::BI__builtin_char_memchr: + BuiltinID = Builtin::BI__builtin_memchr; + break; + case Builtin::BI__builtin___memcpy_chk: { // fold __builtin_memcpy_chk(x, y, cst1, cst2) to memcpy iff cst1<=cst2. llvm::APSInt Size, DstSize; Modified: vendor/clang/dist/lib/Lex/PPMacroExpansion.cpp ============================================================================== --- vendor/clang/dist/lib/Lex/PPMacroExpansion.cpp Tue Jan 24 19:17:58 2017 (r312705) +++ vendor/clang/dist/lib/Lex/PPMacroExpansion.cpp Tue Jan 24 19:18:04 2017 (r312706) @@ -1183,6 +1183,7 @@ static bool HasFeature(const Preprocesso .Case("cxx_attributes", LangOpts.CPlusPlus11) .Case("cxx_auto_type", LangOpts.CPlusPlus11) .Case("cxx_constexpr", LangOpts.CPlusPlus11) + .Case("cxx_constexpr_string_builtins", LangOpts.CPlusPlus11) .Case("cxx_decltype", LangOpts.CPlusPlus11) .Case("cxx_decltype_incomplete_return_types", LangOpts.CPlusPlus11) .Case("cxx_default_function_template_args", LangOpts.CPlusPlus11) Modified: vendor/clang/dist/lib/Sema/SemaDeclCXX.cpp ============================================================================== --- vendor/clang/dist/lib/Sema/SemaDeclCXX.cpp Tue Jan 24 19:17:58 2017 (r312705) +++ vendor/clang/dist/lib/Sema/SemaDeclCXX.cpp Tue Jan 24 19:18:04 2017 (r312706) @@ -12383,9 +12383,9 @@ ExprResult Sema::BuildCXXDefaultInitExpr Diag(Loc, diag::err_in_class_initializer_not_yet_parsed) << OutermostClass << Field; Diag(Field->getLocEnd(), diag::note_in_class_initializer_not_yet_parsed); - - // Don't diagnose this again. - Field->setInvalidDecl(); + // Recover by marking the field invalid, unless we're in a SFINAE context. + if (!isSFINAEContext()) + Field->setInvalidDecl(); return ExprError(); } Modified: vendor/clang/dist/lib/Sema/SemaExpr.cpp ============================================================================== --- vendor/clang/dist/lib/Sema/SemaExpr.cpp Tue Jan 24 19:17:58 2017 (r312705) +++ vendor/clang/dist/lib/Sema/SemaExpr.cpp Tue Jan 24 19:18:04 2017 (r312706) @@ -11496,7 +11496,7 @@ ExprResult Sema::BuildBinOp(Scope *S, So return checkPseudoObjectAssignment(S, OpLoc, Opc, LHSExpr, RHSExpr); // Don't resolve overloads if the other type is overloadable. - if (pty->getKind() == BuiltinType::Overload) { + if (getLangOpts().CPlusPlus && pty->getKind() == BuiltinType::Overload) { // We can't actually test that if we still have a placeholder, // though. Fortunately, none of the exceptions we see in that // code below are valid when the LHS is an overload set. Note @@ -11521,17 +11521,16 @@ ExprResult Sema::BuildBinOp(Scope *S, So // An overload in the RHS can potentially be resolved by the type // being assigned to. if (Opc == BO_Assign && pty->getKind() == BuiltinType::Overload) { - if (LHSExpr->isTypeDependent() || RHSExpr->isTypeDependent()) - return BuildOverloadedBinOp(*this, S, OpLoc, Opc, LHSExpr, RHSExpr); - - if (LHSExpr->getType()->isOverloadableType()) + if (getLangOpts().CPlusPlus && + (LHSExpr->isTypeDependent() || RHSExpr->isTypeDependent() || + LHSExpr->getType()->isOverloadableType())) return BuildOverloadedBinOp(*this, S, OpLoc, Opc, LHSExpr, RHSExpr); return CreateBuiltinBinOp(OpLoc, Opc, LHSExpr, RHSExpr); } // Don't resolve overloads if the other type is overloadable. - if (pty->getKind() == BuiltinType::Overload && + if (getLangOpts().CPlusPlus && pty->getKind() == BuiltinType::Overload && LHSExpr->getType()->isOverloadableType()) return BuildOverloadedBinOp(*this, S, OpLoc, Opc, LHSExpr, RHSExpr); Modified: vendor/clang/dist/test/CodeGenCXX/builtins.cpp ============================================================================== --- vendor/clang/dist/test/CodeGenCXX/builtins.cpp Tue Jan 24 19:17:58 2017 (r312705) +++ vendor/clang/dist/test/CodeGenCXX/builtins.cpp Tue Jan 24 19:18:04 2017 (r312706) @@ -26,3 +26,7 @@ int x = __builtin_abs(-2); long y = __builtin_abs(-2l); // CHECK: [[Y:%.+]] = call i64 @_Z13__builtin_absl(i64 -2) // CHECK: store i64 [[Y]], i64* @y, align 8 + +extern const char char_memchr_arg[32]; +char *memchr_result = __builtin_char_memchr(char_memchr_arg, 123, 32); +// CHECK: call i8* @memchr(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @char_memchr_arg, i32 0, i32 0), i32 123, i64 32) Modified: vendor/clang/dist/test/Lexer/has_feature_cxx0x.cpp ============================================================================== --- vendor/clang/dist/test/Lexer/has_feature_cxx0x.cpp Tue Jan 24 19:17:58 2017 (r312705) +++ vendor/clang/dist/test/Lexer/has_feature_cxx0x.cpp Tue Jan 24 19:18:04 2017 (r312706) @@ -301,6 +301,17 @@ int no_constexpr(); // CHECK-11: has_constexpr // CHECK-NO-11: no_constexpr +#if __has_feature(cxx_constexpr_string_builtins) +int has_constexpr_string_builtins(); +#else +int no_constexpr_string_builtins(); +#endif + +// CHECK-1Z: has_constexpr_string_builtins +// CHECK-14: has_constexpr_string_builtins +// CHECK-11: has_constexpr_string_builtins +// CHECK-NO-11: no_constexpr_string_builtins + #if __has_feature(cxx_generalized_initializers) int has_generalized_initializers(); #else Added: vendor/clang/dist/test/Sema/PR28181.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ vendor/clang/dist/test/Sema/PR28181.c Tue Jan 24 19:18:04 2017 (r312706) @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +struct spinlock_t { + int lock; +} audit_skb_queue; + +void fn1() { + audit_skb_queue = (lock); // expected-error {{use of undeclared identifier 'lock'; did you mean 'long'?}} +} // expected-error@-1 {{assigning to 'struct spinlock_t' from incompatible type ''}} + +void fn2() { + audit_skb_queue + (lock); // expected-error {{use of undeclared identifier 'lock'; did you mean 'long'?}} +} // expected-error@-1 {{reference to overloaded function could not be resolved; did you mean to call it?}} Modified: vendor/clang/dist/test/SemaCXX/constexpr-string.cpp ============================================================================== --- vendor/clang/dist/test/SemaCXX/constexpr-string.cpp Tue Jan 24 19:17:58 2017 (r312705) +++ vendor/clang/dist/test/SemaCXX/constexpr-string.cpp Tue Jan 24 19:18:04 2017 (r312706) @@ -166,6 +166,27 @@ namespace StrchrEtc { static_assert(__builtin_memchr(nullptr, 'x', 3) == nullptr); // expected-error {{not an integral constant}} expected-note {{dereferenced null}} static_assert(__builtin_memchr(nullptr, 'x', 0) == nullptr); // FIXME: Should we reject this? + static_assert(__builtin_char_memchr(kStr, 'a', 0) == nullptr); + static_assert(__builtin_char_memchr(kStr, 'a', 1) == kStr); + static_assert(__builtin_char_memchr(kStr, '\0', 5) == nullptr); + static_assert(__builtin_char_memchr(kStr, '\0', 6) == kStr + 5); + static_assert(__builtin_char_memchr(kStr, '\xff', 8) == kStr + 4); + static_assert(__builtin_char_memchr(kStr, '\xff' + 256, 8) == kStr + 4); + static_assert(__builtin_char_memchr(kStr, '\xff' - 256, 8) == kStr + 4); + static_assert(__builtin_char_memchr(kFoo, 'x', 3) == nullptr); + static_assert(__builtin_char_memchr(kFoo, 'x', 4) == nullptr); // expected-error {{not an integral constant}} expected-note {{dereferenced one-past-the-end}} + static_assert(__builtin_char_memchr(nullptr, 'x', 3) == nullptr); // expected-error {{not an integral constant}} expected-note {{dereferenced null}} + static_assert(__builtin_char_memchr(nullptr, 'x', 0) == nullptr); // FIXME: Should we reject this? + + static_assert(*__builtin_char_memchr(kStr, '\xff', 8) == '\xff'); + constexpr bool char_memchr_mutable() { + char buffer[] = "mutable"; + *__builtin_char_memchr(buffer, 't', 8) = 'r'; + *__builtin_char_memchr(buffer, 'm', 8) = 'd'; + return __builtin_strcmp(buffer, "durable") == 0; + } + static_assert(char_memchr_mutable()); + constexpr bool a = !strchr("hello", 'h'); // expected-error {{constant expression}} expected-note {{non-constexpr function 'strchr' cannot be used in a constant expression}} constexpr bool b = !memchr("hello", 'h', 3); // expected-error {{constant expression}} expected-note {{non-constexpr function 'memchr' cannot be used in a constant expression}} } Added: vendor/clang/dist/test/SemaCXX/cxx11-default-member-initializers.cpp ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ vendor/clang/dist/test/SemaCXX/cxx11-default-member-initializers.cpp Tue Jan 24 19:18:04 2017 (r312706) @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -std=c++11 -verify %s -pedantic + +namespace PR31692 { + struct A { + struct X { int n = 0; } x; + // Trigger construction of X() from a SFINAE context. This must not mark + // any part of X as invalid. + static_assert(!__is_constructible(X), ""); + // Check that X::n is not marked invalid. + double &r = x.n; // expected-error {{non-const lvalue reference to type 'double' cannot bind to a value of unrelated type 'int'}} + }; + // A::X can now be default-constructed. + static_assert(__is_constructible(A::X), ""); +}