Clang 3.3: --analyze produces object file full of XML (plist)

Hi All,

I'm seeing some odd behavior with trying to build libevent under Clang
3.3. Its an auto tools project, but I have things narrowed down to a
clang invocation with and without the --analyze option.

I'm seeing the issue on Mac OS X 10.8.5 (x64) (fully patched) and
Ubuntu 12.10 (x64) (fully patched).

Any ideas on what might be wrong? The compiler never panics.

Jeff

My bad... if anyone is interested in trying to reproduce, fetch
libevent-2.0.21-stable.tar.gz from http://libevent.org/. Then:

$ export CC=/usr/local/bin/clang CXX=/usr/local/bin/clang++
$ ./configure
$ make CC="/usr/local/bin/clang --analyze" CXX="/usr/local/bin/clang++
--analyze"

If you try to pass --analyze through CFLAGS/CXXFLAGS, then configure will die.

Jeff

This is even easier to duplicate:

$ touch event.c
...
$ cat event.c
#include <stdio.h>
int main(int argc, char* argv) {

    return !argc;
}

$ /usr/local/bin/clang --analyze event.c -o event.exe
$ file event.exe
event.exe: XML document text
$

Hello,

This is even easier to duplicate:

$ touch event.c
...
$ cat event.c
#include <stdio.h>
int main(int argc, char* argv) {

   return !argc;
}

$ /usr/local/bin/clang --analyze event.c -o event.exe
$ file event.exe
event.exe: XML document text
$

As far as I know when running the static analyzer (which --analyze does) clang outputs
an XML or HTML file with the analyzer's result, not machine code. So I would guess
everything works as intended.

What is the result you expect?

HTH,
Jonathan

Hello,

This is even easier to duplicate:

$ touch event.c
...
$ cat event.c
#include <stdio.h>
int main(int argc, char* argv) {

   return !argc;
}

$ /usr/local/bin/clang --analyze event.c -o event.exe
$ file event.exe
event.exe: XML document text
$

As far as I know when running the static analyzer (which --analyze does) clang outputs
an XML or HTML file with the analyzer's result, not machine code. So I would guess
everything works as intended.

Thanks Jonathon. (Don't I feel like an ass....).

That sounds a lot like what I do with scan-build to get the HTML pages.

What is the result you expect?

Well, I wanted to invoke the analyzer while building the library (or
in this case, compiling a source file). I wanted the results to go to
stdout (its easier to file bug reports based on the findings).

$ /usr/local/bin/clang --analyze -analyzer-output stdout t.c -o t.exe
clang: warning: argument unused during compilation: '-analyzer-output stdout'

So I guess I should ask: how do I run the analyzer, build the object
files, and print the analyzer's results to the terminal?

Jeff

Hello,

What is the result you expect?

Well, I wanted to invoke the analyzer while building the library (or
in this case, compiling a source file). I wanted the results to go to
stdout (its easier to file bug reports based on the findings).

$ /usr/local/bin/clang --analyze -analyzer-output stdout t.c -o t.exe
clang: warning: argument unused during compilation: '-analyzer-output stdout'

So I guess I should ask: how do I run the analyzer, build the object
files, and print the analyzer's results to the terminal?

From what I know the analyzer cannot be run at the same time as compiling the

program; you have to do a separate run. This page describes how it's done:
<http://clang-analyzer.llvm.org/scan-build.html&gt;\.

Given that the static analyzer is much slower than compilation I don't think
it's wise to run it every time. But you could set it up so it runs e.g. as part
of your unit tests.

HTH,
Jonathan

Hello,

What is the result you expect?

Well, I wanted to invoke the analyzer while building the library (or
in this case, compiling a source file). I wanted the results to go to
stdout (its easier to file bug reports based on the findings).

$ /usr/local/bin/clang --analyze -analyzer-output stdout t.c -o t.exe
clang: warning: argument unused during compilation: '-analyzer-output stdout'

So I guess I should ask: how do I run the analyzer, build the object
files, and print the analyzer's results to the terminal?

From what I know the analyzer cannot be run at the same time as compiling the
program; you have to do a separate run. This page describes how it's done:
<http://clang-analyzer.llvm.org/scan-build.html&gt;\.

Ah, OK. I've been using scan-build. But the last project I acceptance
tested had an upload limit in its bug reporter, so I could not upload
the scan-build results (even after tar'ing).

I think I allowed Microsoft's Visual Studio cross-pollinate here. They
have an /analyze switch too, and it invokes a heavier-weight analysis
during compilation. Microsoft's analyzer is called Enterprise Code
Analysis (/analyze (Enterprise Code Analysis) | Microsoft Docs),
and I thought Clang's analyzer worked the same.

Given that the static analyzer is much slower than compilation I don't think
it's wise to run it every time. But you could set it up so it runs e.g. as part
of your unit tests.

I grinned when I read that. It reminds me of Dr. Jon Bentley's saying:
If it does not have to be correct, I can make it as fast as you'd like
it to be.

When building an external library for possible use, I really don't
care how long it takes to compile and link. But I do care about the
hidden problems uncovered by Clang. (Not meant to be rude - it just my
thinking).

Jeff