From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by sourceware.org (Postfix) with ESMTPS id 58916385800E for ; Mon, 5 Jul 2021 10:42:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 58916385800E Received: by mail-ed1-x52a.google.com with SMTP id m17so1560821edc.9 for ; Mon, 05 Jul 2021 03:42:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Gyfyuwxy4CywKH8OiQ/eu4KEIuMI0wX6eGpxZPHvTLQ=; b=Ln0ikAV77iJpVaojiVkltF2Pu4MiXSYrzTvOwROzABNSYJJiztSiQVrLZGPIgXNKCX E/xpIy3V4IjpqPHKItDatG99Nl4VuQHGlRkeFOVbC60CMh/CrE1yGeCtrqxqDzyW+5OV AorgQmUD0IV4J+wIrECKYGQh3uUjI/SuVaJe0f0oMDlY1lWgS9Mbhz1PnWF+1OVNZY3G b00WrNgU+DUD4JYZGpvWCwcU/HgLJsc24BfltVoMCzF8c8d3j6JLXf8LYeuqIapI77kO IMAcjD+fGxNTAGIyFKDYZoNVdvSx0TQS0XhSeKKZK7irIWEvgl4z46O75wdeeFwZEwU1 DkLg== X-Gm-Message-State: AOAM533SHTGArV/mJhTzdrSlnwwg6kCI47+92ViSXZ/Ngp4KMDtmphc1 PhUhM2EbPKSgmmhDgoaiHuuPiUnLiP1EDDfh5Qg= X-Google-Smtp-Source: ABdhPJwCS7cZoBdLd9+EISzJ5tfzrdmXY8gJ7wPCpouxyE1UzKd6kIw97Yi5+RCFbJUl0TzGMnAksgsmIGvXurM+bJA= X-Received: by 2002:a05:6402:42c9:: with SMTP id i9mr15392054edc.61.1625481754096; Mon, 05 Jul 2021 03:42:34 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Richard Biener Date: Mon, 5 Jul 2021 12:42:23 +0200 Message-ID: Subject: Re: ubsan built-in function types To: Martin Sebor Cc: gcc mailing list Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 05 Jul 2021 10:42:36 -0000 On Fri, Jul 2, 2021 at 6:33 PM Martin Sebor via Gcc wrote: > > Most sanitizer built-in argument types are all of pointer types. > For example: > > BUILT_IN_UBSAN_HANDLE_SHIFT_OUT_OF_BOUNDS > as > BT_FN_VOID_PTR_PTR_PTR > > or > > BUILT_IN_UBSAN_HANDLE_VLA_BOUND_NOT_POSITIVE > as > BT_FN_VOID_PTR_PTR. > > But some calls to these functions are made with some arguments > of integer types. For instance, the sanitized code for the shift > expression below: > > int f (int i, int j) > { > return i << j; > } > > is this: > > : > _9 = (unsigned long) j.0_13; > _10 = (unsigned long) i.1_15; > # .MEM_17 = VDEF <.MEM_16(D)> > __builtin___ubsan_handle_shift_out_of_bounds (&*.Lubsan_data0, _10, _9); > > As a result, gimple_call_builtin_p() returns false for such calls > because the arguments don't match the expected types. Assuming > the function types are that way on purpose, is it expected that > gimple_call_builtin_p() fail for these calls? This API uses gimple_builtin_call_types_compatible to guard these kind of mismatches which makes consumers not need to do extensive argument verification checks. So, yes. > If so, what's > the recommended way to test a statement to see if it's a sanitizer > built-in? Use the head part of the above API: bool gimple_call_builtin_p (const gimple *stmt, enum built_in_function code) { tree fndecl; if (is_gimple_call (stmt) && (fndecl = gimple_call_fndecl (stmt)) != NULL_TREE && fndecl_built_in_p (fndecl, code)) and return true instead of checking for compatible types. > ASAN uses gimple_call_builtin_p (stmt, BUILT_IN_NORMAL)) to see > if a statement is the result of instrumentation (in > has_stmt_been_instrumented_p) and this test fails for the same > reason. I don't know if it matters, I was just looking for > a way to check that succeeds even for these calls. > > Thanks > Martin