From owner-svn-src-all@freebsd.org Sat Feb 22 16:44:11 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 013FE244665; Sat, 22 Feb 2020 16:44:11 +0000 (UTC) (envelope-from mjguzik@gmail.com) Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 48PvL22dgxz4JDK; Sat, 22 Feb 2020 16:44:10 +0000 (UTC) (envelope-from mjguzik@gmail.com) Received: by mail-wr1-x42f.google.com with SMTP id y11so5479131wrt.6; Sat, 22 Feb 2020 08:44:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=ebiuzCMNkzjYtL0Ow5K0WFXTO5c7OcVaC1AHvoFaFVQ=; b=i/nqY0G9cuKqRQ+aZVDvkdM4Y5ghn1HVVSF30lw1mxSWhalZ7SigulKpX8trIa7oUh i2Jb2Y9I54nPMT5hE62y4BolD6cg9e1x68jQB0K/q9YCLSb9kgQIikHVyJBJjXqxK/vO AEemNyo4iyIppXPRcoIsocY59s8MfTIt70jk+9bQvWsUnrHH2DNuC1lSZGnP2Bx8mCZa fUrS0UnALRwdbx8QKPA8yBJKr/lmseBDnelFTa2wzLfZ6ohK39jiwqrDduQavu4NFduF EexnL4kdAChRpx5tu+bm7p2PhePEj7Oim6swYy9x4ccOoVOa4WCFcuYlOWGis9fi614n pmFg== 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=ebiuzCMNkzjYtL0Ow5K0WFXTO5c7OcVaC1AHvoFaFVQ=; b=iM2VAXb+5Nm6GVHiDp71QETErHTWuvcpLN6Lj6y2ezJ0oisV4mql59lWwzynz+7dAo GAbdmcmS5PcXKQuxZh9HWS/mnxrceni+FBYmaGQvmLghkb8rPIvvL7gQT7e0hYDcCWxh bHoClwidW0RA7MrOB5ZA4HAwy9ROg9n8B47obhqUUIbKBZvMvlwQ+Ci1FcRNMquYkl1P kIk3DNm0oU2rdU70bjlSLMyOphvSh0K9nvGIoLrvkJ2bpKN8YovR8W8yJ/FVeZg4q65p 3SOqCqdGnkanFMhfu4IYxiwFjMZcUs7LNp8tlPg25OC7ee8faQ1FPtOdVt12F/RKylaZ K0Vw== X-Gm-Message-State: APjAAAWnEsnVAPAPQxv/YudihBAmwYNhswUKhA6aSZcUmMy0slKjNHwq 3IMYI4g5TfGU58bJAslDdl1SVU57dZXSsuravKfsyw== X-Google-Smtp-Source: APXvYqxBgwxZ1dJ6CSXIfC9ymeIt4fYfegNUYlbvlPlRaCIGfYTA8KF0RSJ+ACa8RLzo8enXfMet+elJxDos/2z1N3U= X-Received: by 2002:a05:6000:1187:: with SMTP id g7mr55900655wrx.109.1582389845888; Sat, 22 Feb 2020 08:44:05 -0800 (PST) MIME-Version: 1.0 Received: by 2002:a5d:6b02:0:0:0:0:0 with HTTP; Sat, 22 Feb 2020 08:44:04 -0800 (PST) In-Reply-To: References: <202002221620.01MGK46E072303@repo.freebsd.org> From: Mateusz Guzik Date: Sat, 22 Feb 2020 17:44:04 +0100 Message-ID: Subject: Re: svn commit: r358248 - head/sys/vm To: Kyle Evans Cc: Ian Lepore , svn-src-head , svn-src-all , src-committers Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: 48PvL22dgxz4JDK X-Spamd-Bar: ----- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-6.00 / 15.00]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; REPLY(-4.00)[] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 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: Sat, 22 Feb 2020 16:44:11 -0000 On 2/22/20, Kyle Evans wrote: > On Sat, Feb 22, 2020 at 10:25 AM Ian Lepore wrote: >> >> On Sat, 2020-02-22 at 16:20 +0000, Kyle Evans wrote: >> > Author: kevans >> > Date: Sat Feb 22 16:20:04 2020 >> > New Revision: 358248 >> > URL: https://svnweb.freebsd.org/changeset/base/358248 >> > >> > Log: >> > vm_radix: prefer __builtin_unreachable() to an unreachable panic() >> > >> > This provides the needed hint to GCC and offers an annotation for >> > readers to >> > observe that it's in-fact impossible to hit this point. We'll get hit >> > with a >> > a -Wswitch error if the enum applicable to the switch above were to >> > get >> > expanded without the new value(s) being handled. >> > >> > Modified: >> > head/sys/vm/vm_radix.c >> > >> > Modified: head/sys/vm/vm_radix.c >> > ============================================================================== >> > --- head/sys/vm/vm_radix.c Sat Feb 22 13:23:27 2020 (r358247) >> > +++ head/sys/vm/vm_radix.c Sat Feb 22 16:20:04 2020 (r358248) >> > @@ -208,8 +208,7 @@ vm_radix_node_load(smrnode_t *p, enum >> > vm_radix_access >> > case SMR: >> > return (smr_entered_load(p, vm_radix_smr)); >> > } >> > - /* This is unreachable, silence gcc. */ >> > - panic("vm_radix_node_get: Unknown access type"); >> > + __unreachable(); >> > } >> > >> > static __inline void >> >> What does __unreachable() do if the code ever becomes reachable? Like >> if a new enum value is added and this switch doesn't get updated? >> > > __unreachable doesn't help here, but the compiler will error out on > the switch() if all enum values aren't addressed and there's no > default: case. > > IMO, compilers could/should become smart enough to error if there's an > explicit __builtin_unreachable() and they can trivially determine that > all paths will terminate before this, independent of -Werror=switch*. > _______________________________________________ I think this is way too iffy, check this program: #include int main(void) { __builtin_unreachable(); printf("test\n"); } Neither clang nor gcc warn about this and both stop code generation past the statement. Thus I think for production kernels __unreachable can expand to to the builtin, but for debug it should be a panic with func/file/line. This would work fine in terms of analysis since panic is noreturn or so. -- Mateusz Guzik