3

I am trying to generate mutants for a code (with an AST based mutant generator) which in order to compile uses -D macros. I am able to use clang to generate an AST dump using this command

clang -Xclang -ast-dump -fsyntax-only -DFLAG=0 -DOTHER_FLAG file.c

But, the mutant generator tool (Milu) uses libclang to parse the c code and generate the AST. Without these macros, libclang is not able to parse the code properly, and it's not possible to add the #defines in the code. I want to set these -D macros globally.

For example, I can set an environment variable C_INCLUDE_PATH which is read by libclang. I am wondering if I can do something similar for -D macros.

Mats Petersson
  • 126,704
  • 14
  • 140
  • 227
Nishant Sharma
  • 683
  • 9
  • 16
  • You will need to pass those in to your compiler instance in some way. There is no environment variables for "defines", only lbraries and include locations. – Mats Petersson May 31 '16 at 05:46
  • I was wondering if there is a global configuration file for clang as well like _configure.ac_ for gcc. – Nishant Sharma May 31 '16 at 14:48

1 Answers1

2

Just pass them when creating your CXTranslationUnit. The relevant function clang_createTranslationUnit takes arguments similar to argv and argc.

Daniel Jour
  • 15,896
  • 2
  • 36
  • 63