Static Validation of C Preprocessor Macros

被引:3
|
作者
Saebjornsen, Andreas [1 ]
Jiang, Lingxiao [1 ]
Quinlan, Daniel [2 ]
Su, Zhendong [1 ]
机构
[1] Univ Calif Davis, Davis, CA 95616 USA
[2] Lawrence Livermore Natl Lab, Livermore, CA USA
基金
美国国家科学基金会;
关键词
preprossing; macro errors; inconsistencies;
D O I
10.1109/ASE.2009.75
中图分类号
TP31 [计算机软件];
学科分类号
081202 ; 0835 ;
摘要
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.
引用
收藏
页码:149 / 160
页数:12
相关论文
共 50 条
  • [1] A generic preprocessor for program validation and debugging
    Puebla, G
    Bueno, F
    Hermenegildo, M
    [J]. ANALYSIS AND VISUALIZATION TOOLS FOR CONSTRAINT PROGRAMMING, 2000, 1870 : 63 - 107
  • [2] A Foundation for Refactoring C with Macros
    Overbey, Jeffrey L.
    Behrang, Farnaz
    Hafiz, Munawar
    [J]. 22ND ACM SIGSOFT INTERNATIONAL SYMPOSIUM ON THE FOUNDATIONS OF SOFTWARE ENGINEERING (FSE 2014), 2014, : 75 - 85
  • [3] The new C: X macros
    Meyers, R.
    [J]. C/C++ Users Journal, 2001, 19 (05):
  • [4] MACROS FOR DEFINING C++ CLASSES
    WEISERT, C
    [J]. SIGPLAN NOTICES, 1992, 27 (11): : 67 - 76
  • [5] A preprocessor approach to persistent C++
    Evrendilek, C
    Dogac, A
    Gesli, T
    [J]. ADVANCES IN DATABASES AND INFORMATION SYSTEMS, 1996, : 235 - 251
  • [6] An empirical analysis of C preprocessor use
    Ernst, MD
    Badros, GJ
    Notkin, D
    [J]. IEEE TRANSACTIONS ON SOFTWARE ENGINEERING, 2002, 28 (12) : 1146 - 1170
  • [7] Embracing the C preprocessor during refactoring
    Garrido, Alejandra
    Johnson, Ralph
    [J]. JOURNAL OF SOFTWARE-EVOLUTION AND PROCESS, 2013, 25 (12) : 1285 - 1304
  • [8] Static data-flow analysis for software product lines in C Revoking the preprocessor's special role
    Schubert, Philipp Dominik
    Gazzillo, Paul
    Patterson, Zach
    Braha, Julian
    Schiebel, Fabian
    Hermann, Ben
    Wei, Shiyi
    Bodden, Eric
    [J]. AUTOMATED SOFTWARE ENGINEERING, 2022, 29 (01)
  • [9] Statistical Static Timing Analysis Flow for Transistor Level Macros in a Microprocessor
    Nandakumar, Vivek S.
    Newmark, David
    Zhan, Yaping
    Marek-Sadowska, Malgorzata
    [J]. PROCEEDINGS OF THE ELEVENTH INTERNATIONAL SYMPOSIUM ON QUALITY ELECTRONIC DESIGN (ISQED 2010), 2010, : 163 - 170
  • [10] D-FLAT AND THE C-PREPROCESSOR
    STEVENS, A
    [J]. DR DOBBS JOURNAL, 1991, 16 (09): : 109 - +