Static validation of C preprocessor macros
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 t...
Saved in:
Main Authors: | , , , |
---|---|
Format: | text |
Language: | English |
Published: |
Institutional Knowledge at Singapore Management University
2009
|
Subjects: | |
Online Access: | https://ink.library.smu.edu.sg/sis_research/495 https://ink.library.smu.edu.sg/context/sis_research/article/1494/viewcontent/ase09macros.pdf |
Tags: |
Add Tag
No Tags, Be the first to tag this record!
|
Institution: | Singapore Management University |
Language: | English |
id |
sg-smu-ink.sis_research-1494 |
---|---|
record_format |
dspace |
spelling |
sg-smu-ink.sis_research-14942017-04-17T02:20:51Z Static validation of C preprocessor macros SAEBJORNSEN, Andreas JIANG, Lingxiao Quinlan, Daniel SU, Zhendong 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. 2009-11-01T07:00:00Z text application/pdf https://ink.library.smu.edu.sg/sis_research/495 info:doi/10.1109/ASE.2009.75 https://ink.library.smu.edu.sg/context/sis_research/article/1494/viewcontent/ase09macros.pdf http://creativecommons.org/licenses/by-nc-nd/4.0/ Research Collection School Of Computing and Information Systems eng Institutional Knowledge at Singapore Management University preprossing macro errors inconsistencies Software Engineering |
institution |
Singapore Management University |
building |
SMU Libraries |
continent |
Asia |
country |
Singapore Singapore |
content_provider |
SMU Libraries |
collection |
InK@SMU |
language |
English |
topic |
preprossing macro errors inconsistencies Software Engineering |
spellingShingle |
preprossing macro errors inconsistencies Software Engineering SAEBJORNSEN, Andreas JIANG, Lingxiao Quinlan, Daniel SU, Zhendong Static validation of C preprocessor macros |
description |
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. |
format |
text |
author |
SAEBJORNSEN, Andreas JIANG, Lingxiao Quinlan, Daniel SU, Zhendong |
author_facet |
SAEBJORNSEN, Andreas JIANG, Lingxiao Quinlan, Daniel SU, Zhendong |
author_sort |
SAEBJORNSEN, Andreas |
title |
Static validation of C preprocessor macros |
title_short |
Static validation of C preprocessor macros |
title_full |
Static validation of C preprocessor macros |
title_fullStr |
Static validation of C preprocessor macros |
title_full_unstemmed |
Static validation of C preprocessor macros |
title_sort |
static validation of c preprocessor macros |
publisher |
Institutional Knowledge at Singapore Management University |
publishDate |
2009 |
url |
https://ink.library.smu.edu.sg/sis_research/495 https://ink.library.smu.edu.sg/context/sis_research/article/1494/viewcontent/ase09macros.pdf |
_version_ |
1770570442044604416 |