From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2209) id 412FC3858417; Tue, 22 Nov 2022 22:32:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 412FC3858417 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669156366; bh=LWLb3OYsSX8GZf9IdEJjj+tbwNxBs02fdcpk9Oj86p0=; h=From:To:Subject:Date:From; b=TCdt2NiotJDwbykB9jyy5M0QpzODcIz8ttUiGXj6dV4R7xYtFCJ1FU4qH90EvvVS4 tPT/GExTyWW0QFdPS1g+5/iv3GYPlX4LJZUx1JGoCBhzP/NpQqQGGHNwFHqVeDbQRz 2F9kb7M3P034ZqIzLMzRXJxNCK6iRwrmHhaZEoNU= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: David Malcolm To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-4247] analyzer: fix 'errno' on Solaris and OS X [PR107807] X-Act-Checkin: gcc X-Git-Author: David Malcolm X-Git-Refname: refs/heads/master X-Git-Oldrev: 6bd31b33daa3c7635d886ff2cebd915748db2084 X-Git-Newrev: 7c9717fcb5cf94ce1e7ef5c903058adf9980ff28 Message-Id: <20221122223246.412FC3858417@sourceware.org> Date: Tue, 22 Nov 2022 22:32:46 +0000 (GMT) List-Id: https://gcc.gnu.org/g:7c9717fcb5cf94ce1e7ef5c903058adf9980ff28 commit r13-4247-g7c9717fcb5cf94ce1e7ef5c903058adf9980ff28 Author: David Malcolm Date: Tue Nov 22 17:29:21 2022 -0500 analyzer: fix 'errno' on Solaris and OS X [PR107807] gcc/analyzer/ChangeLog: PR analyzer/107807 * region-model-impl-calls.cc (register_known_functions): Register "___errno" and "__error" as synonyms for "__errno_location". gcc/testsuite/ChangeLog: PR analyzer/107807 * gcc.dg/analyzer/errno-___errno.c: New test. * gcc.dg/analyzer/errno-__error.c: New test. * gcc.dg/analyzer/errno-global-var.c: New test. Signed-off-by: David Malcolm Diff: --- gcc/analyzer/region-model-impl-calls.cc | 14 ++++++++++++ gcc/testsuite/gcc.dg/analyzer/errno-___errno.c | 29 ++++++++++++++++++++++++ gcc/testsuite/gcc.dg/analyzer/errno-__error.c | 28 +++++++++++++++++++++++ gcc/testsuite/gcc.dg/analyzer/errno-global-var.c | 26 +++++++++++++++++++++ 4 files changed, 97 insertions(+) diff --git a/gcc/analyzer/region-model-impl-calls.cc b/gcc/analyzer/region-model-impl-calls.cc index 6962ffd400f..23a21d752cf 100644 --- a/gcc/analyzer/region-model-impl-calls.cc +++ b/gcc/analyzer/region-model-impl-calls.cc @@ -1953,6 +1953,20 @@ register_known_functions (known_function_manager &kfm) kfm.add ("error_at_line", make_unique (5)); } + /* Other implementations of C standard library. */ + { + /* According to PR 107807 comment #2, Solaris implements "errno" + like this: + extern int *___errno(void) __attribute__((__const__)); + #define errno (*(___errno())) + and OS X like this: + extern int * __error(void); + #define errno (*__error()) + Add these as synonyms for "__errno_location". */ + kfm.add ("___errno", make_unique ()); + kfm.add ("__error", make_unique ()); + } + /* C++ support functions. */ { kfm.add ("operator new", make_unique ()); diff --git a/gcc/testsuite/gcc.dg/analyzer/errno-___errno.c b/gcc/testsuite/gcc.dg/analyzer/errno-___errno.c new file mode 100644 index 00000000000..17ff8b7de9d --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/errno-___errno.c @@ -0,0 +1,29 @@ +#include "analyzer-decls.h" + +/* According to PR 107807 comment #2, Solaris implements "errno" + like this: */ + +extern int *___errno(void) __attribute__((__const__)); +#define errno (*(___errno())) + + +extern void external_fn (void); + +int test_reading_errno (void) +{ + return errno; +} + +void test_setting_errno (int val) +{ + errno = val; +} + +void test_storing_to_errno (int val) +{ + __analyzer_eval (errno == val); /* { dg-warning "UNKNOWN" } */ + errno = val; + __analyzer_eval (errno == val); /* { dg-warning "TRUE" } */ + external_fn (); + __analyzer_eval (errno == val); /* { dg-warning "UNKNOWN" } */ +} diff --git a/gcc/testsuite/gcc.dg/analyzer/errno-__error.c b/gcc/testsuite/gcc.dg/analyzer/errno-__error.c new file mode 100644 index 00000000000..19bc4f937f6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/errno-__error.c @@ -0,0 +1,28 @@ +#include "analyzer-decls.h" + +/* According to PR 107807 comment #2, OS X implements "errno" + like this: */ + +extern int * __error(void); +#define errno (*__error()) + +extern void external_fn (void); + +int test_reading_errno (void) +{ + return errno; +} + +void test_setting_errno (int val) +{ + errno = val; +} + +void test_storing_to_errno (int val) +{ + __analyzer_eval (errno == val); /* { dg-warning "UNKNOWN" } */ + errno = val; + __analyzer_eval (errno == val); /* { dg-warning "TRUE" } */ + external_fn (); + __analyzer_eval (errno == val); /* { dg-warning "UNKNOWN" } */ +} diff --git a/gcc/testsuite/gcc.dg/analyzer/errno-global-var.c b/gcc/testsuite/gcc.dg/analyzer/errno-global-var.c new file mode 100644 index 00000000000..fdf1b17cecc --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/errno-global-var.c @@ -0,0 +1,26 @@ +#include "analyzer-decls.h" + +/* "errno" declared as a global var. */ + +extern int errno; + +extern void external_fn (void); + +int test_reading_errno (void) +{ + return errno; +} + +void test_setting_errno (int val) +{ + errno = val; +} + +void test_storing_to_errno (int val) +{ + __analyzer_eval (errno == val); /* { dg-warning "UNKNOWN" } */ + errno = val; + __analyzer_eval (errno == val); /* { dg-warning "TRUE" } */ + external_fn (); + __analyzer_eval (errno == val); /* { dg-warning "UNKNOWN" } */ +}