DocumentCode :
1852072
Title :
Static Validation of C Preprocessor Macros
Author :
Saebjernsen, A. ; Jiang, Lingxiao ; Quinlan, Daniel ; Su, Zhendong
Author_Institution :
Univ. of California, Davis, CA, USA
fYear :
2009
fDate :
16-20 Nov. 2009
Firstpage :
149
Lastpage :
160
Abstract :
The widely used C preprocessor (CPP) is generally considered a source of difficulty for understanding and maintaining C/C++ programs. The main reason for this difficulty is CPP´s purely lexical semantics, i.e., its treatment of both input and output as token streams. This can easily lead to errors that are difficult to diagnose, and it has been estimated that up to 20% of all macros are erroneous. To reduce such errors, more restrictive, replacement languages for CPP have been proposed to limit expanded macros to be valid C syntactic units. However, there is no practical tool that can effectively validate CPP macros in legacy applications. In this paper, we introduce a novel, general characterization of inconsistent macro usage as a strong indicator of macro errors. Our key insight is that all applications of the same macro should behave similarly. In particular, we map each macro call c in a source file f to c´s normalized syntactic constructs within the abstract syntax tree (AST) for f´s preprocessed source, and use syntactic similarity as the basis for comparing macro calls of the same macro definition. Utilizing this characterization, we have developed an efficient algorithm to statically validate macro usage in C/C++ programs. We have implemented the algorithm; evaluation results show that our tool is effective in detecting common macro-related errors and reports few false positives, making it a practical tool for validating macro usage.
Keywords :
C++ language; macros; program diagnostics; program verification; software maintenance; C preprocessor macros; C programs; C syntactic units; C++ programs; abstract syntax tree; legacy applications; lexical semantics; static validation; token streams; Computer languages; Contracts; Engineering profession; Government; Laboratories; Performance analysis; Programming profession; Research and development; Software engineering; Subcontracting; inconsistencies; macro errors; preprossing;
fLanguage :
English
Publisher :
ieee
Conference_Titel :
Automated Software Engineering, 2009. ASE '09. 24th IEEE/ACM International Conference on
Conference_Location :
Auckland
ISSN :
1938-4300
Print_ISBN :
978-1-4244-5259-0
Electronic_ISBN :
1938-4300
Type :
conf
DOI :
10.1109/ASE.2009.75
Filename :
5431774
Link To Document :
بازگشت