A ClangTool question

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

A ClangTool question

Sam McCall via cfe-dev
Hello List,

I am developing a tool to analyze source code that is written for target
compilers (e.g. IAR, Cosmic, Greenhills). Because some of these
compilers use their own data types and keywords (e.g. special function
registers, bit data types, and type modifier huge, far, near) and comes
with own headers, my workflow is as follows.

I use the preprocessor of the target compiler to preprocess the sources.
The preprocessed source is then processed by a lexer to remove or
rewrite constructs that lead to a syntax errors.
Then I use CLangTool.buildATSs to create ASTUnits and processe them with
my ASTVisitor.

That's worked so far. Now I have switched to 64 bit and I am facing the
problem that sources written for 32 bit cannot be compiled anymore.

My question now is, is there a command line option to teach CLangTool
that it has 32 bit source code in front of it? Or do I have to create a
32 and 64 version of my tool first?

Here is an example of code that compiles with 32 bit without errors, but
generates an error with the 64 bit version.

typedef unsigned int size_t;
void* operator new(std::size_t);

error: 'operator new' takes type size_t ('unsigned long long') as first
parameter


Frank

P.S.:
I'm on Windows using MSYS2/MinGW to compile my tool. I have compiled
Clang/LLVM 6.0 with MinGW gcc 7.2.
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: A ClangTool question

Sam McCall via cfe-dev
Am 16.04.2018 um 07:07 schrieb Frank Redeker via cfe-dev:

> Hello List,
>
> I am developing a tool to analyze source code that is written for target
> compilers (e.g. IAR, Cosmic, Greenhills). Because some of these
> compilers use their own data types and keywords (e.g. special function
> registers, bit data types, and type modifier huge, far, near) and comes
> with own headers, my workflow is as follows.
>
> I use the preprocessor of the target compiler to preprocess the sources.
> The preprocessed source is then processed by a lexer to remove or
> rewrite constructs that lead to a syntax errors.
> Then I use CLangTool.buildATSs to create ASTUnits and processe them with
> my ASTVisitor.
>
> That's worked so far. Now I have switched to 64 bit and I am facing the
> problem that sources written for 32 bit cannot be compiled anymore.
>
> My question now is, is there a command line option to teach CLangTool
> that it has 32 bit source code in front of it? Or do I have to create a
> 32 and 64 version of my tool first?
>
> Here is an example of code that compiles with 32 bit without errors, but
> generates an error with the 64 bit version.
>
> typedef unsigned int size_t;
> void* operator new(std::size_t);
>
> error: 'operator new' takes type size_t ('unsigned long long') as first
> parameter
>
>
> Frank
>
> P.S.:
> I'm on Windows using MSYS2/MinGW to compile my tool. I have compiled
> Clang/LLVM 6.0 with MinGW gcc 7.2.

I found the solution myself. The compiler option -m32 switches to 32 bit
mode.

Thank you for your attention.

Frank
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev