Hello,
Your best bet is to define a function with a user attribute in some header:
static inline void __attribute__((user("pointer_ok"))) pointer_ok() {}
static inline void __attribute__((user("pointer_not_ok"))) pointer_not_ok() {}
#define POINTER_OK pointer_ok();
#define POINTER_NOT_OK pointer_not_ok();
Incidentally, custom pragmas can be used with a gcc plugin (see
http://gcc.gnu.org/viewcvs/trunk/gcc/testsuite/g%2B%2B.dg/plugin/pragma_plugin.c?view=markup)
but they don't end up as ast nodes (you'll only get whole function
granularity).
As for a pointer exposed by a function call, you can already check
this with dehydra.
Try using a script like this to print the node info:
function process_function(decl, stmts) {
for each (let v in iterate_vars(stmts)) {
do_dehydra_dump(v, 2, 5); // see libs/utils.js
print("---");
}
}
A statement like
foo(/* pointer type */ bar());
results in:
shortName: 'foo'
name: 'foo(int*)'
isFunction: true
parameters: object
0: object
shortName: 'x'
name: 'x'
type: object
isPointer: true
precision: 64
type: object
min: object
max: object
isSigned: true
precision: 32
name: 'int'
loc: object
_source_location: 1246
file: 'pragma.c'
line: 10
column: 6
toString: object
type: object
type: object
name: 'void'
parameters: object
0: object
isPointer: true
precision: 64
type: object
min: object
max: object
isSigned: true
precision: 32
name: 'int'
loc: object
_source_location: 1246
file: 'pragma.c'
line: 10
column: 6
toString: object
isFcall: true
arguments: object
0: object
shortName: 'bar'
name: 'bar()'
isFunction: true
parameters: object
type: object
type: object
isPointer: true
precision: 64
type: object
parameters: object
loc: object
_source_location: 734
file: 'pragma.c'
line: 6
column: 6
toString: object
isFcall: true
arguments: object
So, somewhat obscurely, for each element of the arguments array you'll
need to check type.type.isPointer when dealing with embedded function
calls.
Also, although you should get identical results regardless, I would
highly recommend using GCC 4.5.
Cheers,
Ehren
On Sat, Jul 10, 2010 at 11:42 PM, Ehren Metcalfe <[email protected]> wrote:
> Hello,
>
> Your best bet is to define a function with a user attribute in some header:
>
> static inline void __attribute__((user("pointer_ok"))) pointer_ok() {}
> static inline void __attribute__((user("pointer_not_ok"))) pointer_not_ok() {}
> #define POINTER_OK pointer_ok();
> #define POINTER_NOT_OK pointer_not_ok();
>
> Incidentally, custom pragmas can be used with a gcc plugin (see
> http://gcc.gnu.org/viewcvs/trunk/gcc/testsuite/g%2B%2B.dg/plugin/pragma_plugin.c?view=markup)
> but they don't end up as ast nodes (you'll only get whole function
> granularity).
>
> As for a pointer exposed by a function call, you can already check
> this with dehydra.
>
> Try using a script like this to print the node info:
>
> function process_function(decl, stmts) {
> for each (let v in iterate_vars(stmts)) {
> do_dehydra_dump(v, 2, 5); // see libs/utils.js
> print("---");
> }
> }
>
> A statement like
>
> foo(/* pointer type */ bar());
>
> results in:
>
> shortName: 'foo'
> name: 'foo(int*)'
> isFunction: true
> parameters: object
> 0: object
> shortName: 'x'
> name: 'x'
> type: object
> isPointer: true
> precision: 64
> type: object
> min: object
> max: object
> isSigned: true
> precision: 32
> name: 'int'
> loc: object
> _source_location: 1246
> file: 'pragma.c'
> line: 10
> column: 6
> toString: object
> type: object
> type: object
> name: 'void'
> parameters: object
> 0: object
> isPointer: true
> precision: 64
> type: object
> min: object
> max: object
> isSigned: true
> precision: 32
> name: 'int'
> loc: object
> _source_location: 1246
> file: 'pragma.c'
> line: 10
> column: 6
> toString: object
> isFcall: true
> arguments: object
> 0: object
> shortName: 'bar'
> name: 'bar()'
> isFunction: true
> parameters: object
> type: object
> type: object
> isPointer: true
> precision: 64
> type: object
> parameters: object
> loc: object
> _source_location: 734
> file: 'pragma.c'
> line: 6
> column: 6
> toString: object
> isFcall: true
> arguments: object
>
> So, somewhat obscurely, for each element of the arguments array you'll
> need to check type.type.isPointer when dealing with embedded function
> calls.
>
> Also, although you should get identical results regardless, I would
> highly recommend using GCC 4.5.
>
> Cheers,
>
> Ehren
>
> On Sat, Jul 10, 2010 at 9:31 AM, Bartlett, Roscoe A <[email protected]>
> wrote:
>> Hello,
>>
>> I am very interested in trying to use the Dehydra static-analysis plugin for
>> GCC 4.5 to implement some enforcement of the safe memory management classes
>> described here:
>>
>> http://www.cs.sandia.gov/~rabartl/TeuchosMemoryManagementSAND.pdf
>>
>> Basically, I want to be able to turn on a mode on in the code where the
>> custom static analysis tool (that I will write with Dehyra) where all raw
>> pointers will not be allowed, or it will be an error. However, there will
>> likely be places where a raw pointer will need to be exposed for a short
>> period of time. In this cases I would like to be able to temporarily turn
>> off the the checking and then turn it back on again.
>>
>> The problem is that I don't see a way to do this with Dehydra given what is
>> documented at:
>>
>> https://developer.mozilla.org/en/Dehydra
>>
>> I would like to use something like a pragma or something but it does not
>> look like that info is given in the parse tree. Otherwise, I don't know how
>> I can do this.
>>
>> Also, I would need ways to detect when a raw pointer was exposed in a direct
>> function call such as with:
>>
>> someFuncTakingRawPtr( someFuncReturningRawPtr(...) );
>>
>> It does not look like Dehydra exposes temporary variables that are managed
>> by the compiler.
>>
>> I guess that I need to get the Dehydra plug-inn working with GCC 4.5 and see
>> what kinds of info it does actually spit out. Perhaps it already returns
>> temporary objects from function calls?
>>
>> Thanks,
>>
>> - Ross
>>
>>
>> -----------------------------------------------------------------------
>> Dr. Roscoe A. Bartlett
>> Sandia National Laboratories
>> Department of Optimization and Uncertainty Estimation
>> Trilinos Software Engineering Technologies and Integration Lead
>> (505) 844-5097
>>
>>
>>
>> _______________________________________________
>> dev-static-analysis mailing list
>> [email protected]
>> https://lists.mozilla.org/listinfo/dev-static-analysis
>>
>
_______________________________________________
dev-static-analysis mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-static-analysis