alwayszero function attribute for gcc

ASSIGNED
Assigned to

Status

()

Core
Rewriting and Analysis
ASSIGNED
8 years ago
8 years ago

People

(Reporter: (dormant account), Assigned: Ehren Metcalfe)

Tracking

(Blocks: 1 bug, {student-project})

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(4 attachments)

(Reporter)

Description

8 years ago
In mozilla we have a lot of functions that always return NS_OK(0). This means that callers of such functions usually have unneeded error checking.

nsresult rv = call();
if (NS_FAILED(rv)....)  <-- gcc should be able to optimize this away if it knows that value of call() is always zero

For reference see gcc function attributes: pure, const. and Gcc variable attribute nonnull(I don't see that one in the docs anymore, is it gone?).
Keywords: student-project
(Reporter)

Comment 1

8 years ago
alternatively/additionally we should do static analysis to ensure that always zerofunctions
a) only ever return 0
b) never have their return value checked
Assignee: nobody → ehren.m
Status: NEW → ASSIGNED
(Assignee)

Comment 2

8 years ago
Created attachment 416040 [details] [diff] [review]
New static checking pass for NS_alwayszero functions

This has a problem with being able to print off the class location of a method with a misapplied attribute. Being a ripoff of outparams.js, there may still be some unnecessary code as well.
(Assignee)

Comment 3

8 years ago
Created attachment 416041 [details] [diff] [review]
static checking pass plus a patch for less than a third of the identified functions

there are some indenting issues here, particularly when a declaration is broken over several lines.
(Assignee)

Comment 4

8 years ago
Created attachment 416042 [details]
GCC optimization plugin (requires plugin framework from GCC 4.5)
(Assignee)

Comment 5

8 years ago
Created attachment 416043 [details]
Makefile for alwayszero_plugin.c

compile with make CC=/path/to/plugin-enabled/gcc (requires plugin framework from GCC 4.5)
(Assignee)

Updated

8 years ago
Attachment #416042 - Attachment mime type: text/x-csrc → text/plain
(Assignee)

Updated

8 years ago
Attachment #416043 - Attachment mime type: application/octet-stream → text/plain
(Assignee)

Comment 6

8 years ago
Not sure if all of this is ready for review yet. For one thing when FIND_NEW_FUNCTIONS = true, a whole lot of output will be printed during static analysis builds. There's also a lot more patching to be done (likely with Pork).
You need to log in before you can comment on or make changes to this bug.