From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 95891 invoked by alias); 5 Dec 2017 14:24:44 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 95805 invoked by uid 89); 5 Dec 2017 14:24:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.7 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy= X-HELO: mail-it0-f41.google.com Received: from mail-it0-f41.google.com (HELO mail-it0-f41.google.com) (209.85.214.41) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 05 Dec 2017 14:24:37 +0000 Received: by mail-it0-f41.google.com with SMTP id r6so1867282itr.3 for ; Tue, 05 Dec 2017 06:24:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=PK0TRhHt1P4zfLP7A5+53Y1FA9uTQHlZygWVetmQkP8=; b=uLfOlpvklO+yUjzhe6Dd3vcV8kJs3EJIy33ji7tVol2JaRCWI7+IsRYDQcWI1azILb vW07KhRh/cqnJ2Ef4DD+GObyZdXZnpRnQPcQ093Z2T1y9xwDUf9ofBWr0/80H62du1VY 0/Rax9we97qbAj6IsnrbfAwNxDkDJS4eKiGA483cnqGLFZbWNTFMSr44Byb9kr4Z+LQW GYwPJAR502QT6CyvSB+Gt50p7QEGiy9m/Re6J9lIYtM4OJO7detE9MVqCqxewT61lgwO vHx9UDyioeQOVcKuuuu7Jt3zbNDxUpBgCrJNnKJX/rtxrq96/QVBJeC27DHr9z14BuU+ swZA== X-Gm-Message-State: AKGB3mLpSvJpX9aBHbrXnmSyri5E1YrTRISaE/zB5HSFtm+mjPEFixH5 s0zf4lb7BGlx2b2CHHEWR7i2EFmKJnCsbWfVcRIgBA== X-Google-Smtp-Source: AGs4zMacRCuv/yoltaRw/22blq0Z06XmcRmGJo3KLHbJKDi3ul73kYIlyMTSFpr0dBBol99iWcuwtLzbTTh/ZoWVF04= X-Received: by 10.36.17.15 with SMTP id 15mr18994352itf.53.1512483867539; Tue, 05 Dec 2017 06:24:27 -0800 (PST) MIME-Version: 1.0 Received: by 10.107.137.195 with HTTP; Tue, 5 Dec 2017 06:24:07 -0800 (PST) In-Reply-To: <20171205123318.GT2353@tucnak> References: <20171205123318.GT2353@tucnak> From: Jason Merrill Date: Tue, 05 Dec 2017 14:24:00 -0000 Message-ID: Subject: Re: C++ PATCH for c++/79228, complex literal suffixes To: Jakub Jelinek Cc: gcc-patches List , David Malcolm Content-Type: text/plain; charset="UTF-8" X-IsSubscribed: yes X-SW-Source: 2017-12/txt/msg00225.txt.bz2 OK, thanks. On Tue, Dec 5, 2017 at 7:33 AM, Jakub Jelinek wrote: > On Fri, Dec 01, 2017 at 03:16:23PM -0500, Jason Merrill wrote: >> commit e39b7d506d236ce7ef9f64d1bcf0b384bb2d8038 >> Author: Jason Merrill >> Date: Fri Dec 1 07:45:03 2017 -0500 >> >> PR c++/79228 - extensions hide C++14 complex literal operators >> >> libcpp/ >> * expr.c (interpret_float_suffix): Ignore 'i' in C++14 and up. >> (interpret_int_suffix): Likewise. >> gcc/cp/ >> * parser.c (cp_parser_userdef_numeric_literal): Be helpful about >> 'i' in C++14 and up. >> >> + /* In C++14 and up these suffixes are in the standard library, so treat >> + them as user-defined literals. */ >> + if (CPP_OPTION (pfile, cplusplus) >> + && CPP_OPTION (pfile, lang) > CLK_CXX11 >> + && (!memcmp (orig_s, "i", orig_len) >> + || !memcmp (orig_s, "if", orig_len) >> + || !memcmp (orig_s, "il", orig_len))) > > This doesn't seem right, it will invoke UB if orig_len > 2 by potentially > accessing bytes beyond 'i' and '\0' in "i" (and for orig_len > 3 also after > "if" or "il"). > If you only want to return 0 if orig_len bytes starting at orig_s are 'i' > or 'i' 'f' or 'i' 'l', then I'd write instead as in the patch below. > Or if memcmp is more readable, at least check orig_len first. > >> + /* In C++14 and up these suffixes are in the standard library, so treat >> + them as user-defined literals. */ >> + if (CPP_OPTION (pfile, cplusplus) >> + && CPP_OPTION (pfile, lang) > CLK_CXX11 >> + && (!memcmp (s, "i", orig_len) >> + || !memcmp (s, "if", orig_len) >> + || !memcmp (s, "il", orig_len))) > > Similarly. Additionally, "if" can't happen here, because we don't allow 'f' > among suffixes. > > So, ok for trunk if it passes testing, or some other form thereof? > > 2017-12-05 Jakub Jelinek > > PR c++/79228 > * expr.c (interpret_float_suffix): Avoid memcmp. > (interpret_int_suffix): Likewise. Don't check for if. > > --- libcpp/expr.c.jj 2017-12-01 22:13:24.000000000 +0100 > +++ libcpp/expr.c 2017-12-05 13:26:57.019683785 +0100 > @@ -280,9 +280,10 @@ interpret_float_suffix (cpp_reader *pfil > them as user-defined literals. */ > if (CPP_OPTION (pfile, cplusplus) > && CPP_OPTION (pfile, lang) > CLK_CXX11 > - && (!memcmp (orig_s, "i", orig_len) > - || !memcmp (orig_s, "if", orig_len) > - || !memcmp (orig_s, "il", orig_len))) > + && orig_s[0] == 'i' > + && (orig_len == 1 > + || (orig_len == 2 > + && (orig_s[1] == 'f' || orig_s[1] == 'l')))) > return 0; > } > > @@ -345,9 +346,8 @@ interpret_int_suffix (cpp_reader *pfile, > them as user-defined literals. */ > if (CPP_OPTION (pfile, cplusplus) > && CPP_OPTION (pfile, lang) > CLK_CXX11 > - && (!memcmp (s, "i", orig_len) > - || !memcmp (s, "if", orig_len) > - || !memcmp (s, "il", orig_len))) > + && s[0] == 'i' > + && (orig_len == 1 || (orig_len == 2 && s[1] == 'l'))) > return 0; > } > > > > Jakub