Re: r292555 - P0426: Make the library implementation of constexpr char_traits a little easier
r292807. Thanks, Hans On Thu, Jan 19, 2017 at 5:22 PM, Richard Smith wrote: > Hans, can we get this onto the Clang 4 release branch (along with the > documentation added in r292558 and fixed in r292559)? This will allow us to > avoid libc++ carrying a version test for Clang, and allow it to cleanly > finish off its implementation of P0426. > > On 19 January 2017 at 16:45, Richard Smith via cfe-commits > wrote: >> >> Author: rsmith >> Date: Thu Jan 19 18:45:35 2017 >> New Revision: 292555 >> >> URL: http://llvm.org/viewvc/llvm-project?rev=292555&view=rev >> Log: >> P0426: Make the library implementation of constexpr char_traits a little >> easier >> by providing a memchr builtin that returns char* instead of void*. >> >> Also add a __has_feature flag to indicate the presence of constexpr forms >> of >> the relevant functions. >> >> Modified: >> cfe/trunk/include/clang/Basic/Builtins.def >> cfe/trunk/lib/AST/ExprConstant.cpp >> cfe/trunk/lib/CodeGen/CGBuiltin.cpp >> cfe/trunk/lib/Lex/PPMacroExpansion.cpp >> cfe/trunk/test/CodeGenCXX/builtins.cpp >> cfe/trunk/test/Lexer/has_feature_cxx0x.cpp >> cfe/trunk/test/SemaCXX/constexpr-string.cpp >> >> Modified: cfe/trunk/include/clang/Basic/Builtins.def >> URL: >> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.def?rev=292555&r1=292554&r2=292555&view=diff >> >> == >> --- cfe/trunk/include/clang/Basic/Builtins.def (original) >> +++ cfe/trunk/include/clang/Basic/Builtins.def Thu Jan 19 18:45:35 2017 >> @@ -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: cfe/trunk/lib/AST/ExprConstant.cpp >> URL: >> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=292555&r1=292554&r2=292555&view=diff >> >> == >> --- cfe/trunk/lib/AST/ExprConstant.cpp (original) >> +++ cfe/trunk/lib/AST/ExprConstant.cpp Thu Jan 19 18:45:35 2017 >> @@ -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: cfe/trunk/lib/CodeGen/CGBuiltin.cpp >> URL: >> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=292555&r1=292554&r2=292555&view=diff >> >> == >> --- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original) >> +++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Thu Jan 19 18:45:35 2017 >> @@ -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: cfe/trunk/lib/Lex/PPMacroExpansion.cpp >> URL: >> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=292555&r1=292554&r2=292555&view=diff >> >> == >> --- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original) >> +++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Thu Jan 19 18:45:35 2017 >> @@ -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: cfe/trunk/test/CodeGenCXX/builtins.cpp >> URL: >> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/builtins.cpp?rev=292555&r1=292554&r2=292555&view=diff >> >> =
Re: r292555 - P0426: Make the library implementation of constexpr char_traits a little easier
Hans, can we get this onto the Clang 4 release branch (along with the documentation added in r292558 and fixed in r292559)? This will allow us to avoid libc++ carrying a version test for Clang, and allow it to cleanly finish off its implementation of P0426. On 19 January 2017 at 16:45, Richard Smith via cfe-commits < cfe-commits@lists.llvm.org> wrote: > Author: rsmith > Date: Thu Jan 19 18:45:35 2017 > New Revision: 292555 > > URL: http://llvm.org/viewvc/llvm-project?rev=292555&view=rev > Log: > P0426: Make the library implementation of constexpr char_traits a little > easier > by providing a memchr builtin that returns char* instead of void*. > > Also add a __has_feature flag to indicate the presence of constexpr forms > of > the relevant functions. > > Modified: > cfe/trunk/include/clang/Basic/Builtins.def > cfe/trunk/lib/AST/ExprConstant.cpp > cfe/trunk/lib/CodeGen/CGBuiltin.cpp > cfe/trunk/lib/Lex/PPMacroExpansion.cpp > cfe/trunk/test/CodeGenCXX/builtins.cpp > cfe/trunk/test/Lexer/has_feature_cxx0x.cpp > cfe/trunk/test/SemaCXX/constexpr-string.cpp > > Modified: cfe/trunk/include/clang/Basic/Builtins.def > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/ > clang/Basic/Builtins.def?rev=292555&r1=292554&r2=292555&view=diff > > == > --- cfe/trunk/include/clang/Basic/Builtins.def (original) > +++ cfe/trunk/include/clang/Basic/Builtins.def Thu Jan 19 18:45:35 2017 > @@ -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: cfe/trunk/lib/AST/ExprConstant.cpp > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ > ExprConstant.cpp?rev=292555&r1=292554&r2=292555&view=diff > > == > --- cfe/trunk/lib/AST/ExprConstant.cpp (original) > +++ cfe/trunk/lib/AST/ExprConstant.cpp Thu Jan 19 18:45:35 2017 > @@ -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: cfe/trunk/lib/CodeGen/CGBuiltin.cpp > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ > CGBuiltin.cpp?rev=292555&r1=292554&r2=292555&view=diff > > == > --- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original) > +++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Thu Jan 19 18:45:35 2017 > @@ -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: cfe/trunk/lib/Lex/PPMacroExpansion.cpp > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/ > PPMacroExpansion.cpp?rev=292555&r1=292554&r2=292555&view=diff > > == > --- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original) > +++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Thu Jan 19 18:45:35 2017 > @@ -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: cfe/trunk/test/CodeGenCXX/builtins.cpp > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ > CodeGenCXX/builtins.cpp?rev=292555&r1=292554&r2=292555&view=diff > > == > --- cfe/trunk/test/CodeGenCXX/builtins.cpp (original) > +++ cfe/trunk/test/CodeGenCXX/builtins.cpp Thu Ja
r292555 - P0426: Make the library implementation of constexpr char_traits a little easier
Author: rsmith Date: Thu Jan 19 18:45:35 2017 New Revision: 292555 URL: http://llvm.org/viewvc/llvm-project?rev=292555&view=rev Log: P0426: Make the library implementation of constexpr char_traits a little easier by providing a memchr builtin that returns char* instead of void*. Also add a __has_feature flag to indicate the presence of constexpr forms of the relevant functions. Modified: cfe/trunk/include/clang/Basic/Builtins.def cfe/trunk/lib/AST/ExprConstant.cpp cfe/trunk/lib/CodeGen/CGBuiltin.cpp cfe/trunk/lib/Lex/PPMacroExpansion.cpp cfe/trunk/test/CodeGenCXX/builtins.cpp cfe/trunk/test/Lexer/has_feature_cxx0x.cpp cfe/trunk/test/SemaCXX/constexpr-string.cpp Modified: cfe/trunk/include/clang/Basic/Builtins.def URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.def?rev=292555&r1=292554&r2=292555&view=diff == --- cfe/trunk/include/clang/Basic/Builtins.def (original) +++ cfe/trunk/include/clang/Basic/Builtins.def Thu Jan 19 18:45:35 2017 @@ -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: cfe/trunk/lib/AST/ExprConstant.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=292555&r1=292554&r2=292555&view=diff == --- cfe/trunk/lib/AST/ExprConstant.cpp (original) +++ cfe/trunk/lib/AST/ExprConstant.cpp Thu Jan 19 18:45:35 2017 @@ -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: cfe/trunk/lib/CodeGen/CGBuiltin.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=292555&r1=292554&r2=292555&view=diff == --- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original) +++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Thu Jan 19 18:45:35 2017 @@ -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: cfe/trunk/lib/Lex/PPMacroExpansion.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=292555&r1=292554&r2=292555&view=diff == --- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original) +++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Thu Jan 19 18:45:35 2017 @@ -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: cfe/trunk/test/CodeGenCXX/builtins.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/builtins.cpp?rev=292555&r1=292554&r2=292555&view=diff == --- cfe/trunk/test/CodeGenCXX/builtins.cpp (original) +++ cfe/trunk/test/CodeGenCXX/builtins.cpp Thu Jan 19 18:45:35 2017 @@ -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: cfe/trunk/test/Lexer/has_feature_cxx0x.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/has_