From 1ebc6e6f689dc505bb5706a6fc962a89083a2e16 Mon Sep 17 00:00:00 2001 From: David Mandelin Date: Wed, 9 Jul 2008 10:35:29 -0700 Subject: [PATCH] Bug 443205: outparams.js needs to consider void-return funcs as nofail, r=bsmedberg --- xpcom/analysis/outparams.js | 20 ++++++++++++-------- xpcom/tests/static-checker/Makefile.in | 1 + xpcom/tests/static-checker/o16.cpp | 14 ++++++++++++++ 3 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 xpcom/tests/static-checker/o16.cpp diff --git a/xpcom/analysis/outparams.js b/xpcom/analysis/outparams.js index c95f2b93974..2284c98a14f 100644 --- a/xpcom/analysis/outparams.js +++ b/xpcom/analysis/outparams.js @@ -48,8 +48,7 @@ function process_tree(func_decl) { // Determine outparams and return if function not relevant if (is_constructor(func_decl)) return; let psem = OutparamCheck.prototype.func_param_semantics(func_decl); - if (!psem.some(function(x) x == ps.OUT || x == ps.INOUT)) - return; + if (!psem.some(function(x) x.check)) return; let decl = rectify_function_decl(func_decl); if (decl.resultType != 'nsresult' && decl.resultType != 'PRBool' && decl.resultType != 'void') { @@ -62,7 +61,7 @@ function process_tree(func_decl) { let outparam_list = []; let psem_list = []; for (let i = 0; i < psem.length; ++i) { - if (psem[i] == ps.OUT || psem[i] == ps.INOUT) { + if (psem[i].check) { outparam_list.push(params[i]); psem_list.push(psem[i]); } @@ -638,11 +637,16 @@ OutparamCheck.prototype.logResult = function(rv, msg, kind) { // Parameter Semantics values -- indicates whether a parameter is // an outparam. +// label Used for debugging output +// val Abstract value (state) that holds on an argument after +// a call +// check True if parameters with this semantics should be +// checked by this analysis let ps = { - OUTNOFAIL: { label: 'out-no-fail', val: av.WRITTEN }, - OUT: { label: 'out', val: av.WRITTEN }, - INOUT: { label: 'inout', val: av.WRITTEN }, - MAYBE: { label: 'maybe', val: av.MAYBE_WRITTEN}, // maybe out + OUTNOFAIL: { label: 'out-no-fail', val: av.WRITTEN, check: true }, + OUT: { label: 'out', val: av.WRITTEN, check: true }, + INOUT: { label: 'inout', val: av.WRITTEN, check: true }, + MAYBE: { label: 'maybe', val: av.MAYBE_WRITTEN}, // maybe out CONST: { label: 'const' } // i.e. not out }; @@ -653,7 +657,7 @@ OutparamCheck.prototype.func_param_semantics = function(callable) { if (TREE_CODE(ftype) == POINTER_TYPE) ftype = TREE_TYPE(ftype); // What failure semantics to use for outparams let rtype = TREE_TYPE(ftype); - let nofail = rtype == VOID_TYPE; + let nofail = TREE_CODE(rtype) == VOID_TYPE; // Whether to guess outparams by type let guess = type_string(rtype) == 'nsresult'; diff --git a/xpcom/tests/static-checker/Makefile.in b/xpcom/tests/static-checker/Makefile.in index 2e370a56f1c..ee9c084662f 100644 --- a/xpcom/tests/static-checker/Makefile.in +++ b/xpcom/tests/static-checker/Makefile.in @@ -95,6 +95,7 @@ OUTPARAMS_PASS_TESTCASES = \ o13.cpp \ o14.cpp \ o15.cpp \ + o16.cpp \ $(NULL) STATIC_FAILURE_TESTCASES = \ diff --git a/xpcom/tests/static-checker/o16.cpp b/xpcom/tests/static-checker/o16.cpp new file mode 100644 index 00000000000..023b8a48af5 --- /dev/null +++ b/xpcom/tests/static-checker/o16.cpp @@ -0,0 +1,14 @@ +typedef int PRInt32; +typedef int nsresult; + +void +OutFunc(PRInt32 *out __attribute__((user("NS_outparam")))) +{ + *out = 0; +} + +nsresult TestFunc(PRInt32 *a __attribute__((user("NS_outparam")))) +{ + OutFunc(a); + return 0; +}