Closed Bug 1180549 Opened 9 years ago Closed 9 years ago

Fix a startup crash when using the clang-plugin with clang>3.5

Categories

(Developer Infrastructure :: Source Code Analysis, defect)

defect
Not set
normal

Tracking

(firefox42 fixed)

RESOLVED FIXED
mozilla42
Tracking Status
firefox42 --- fixed

People

(Reporter: ehsan.akhgari, Assigned: ehsan.akhgari)

References

Details

Attachments

(1 file)

The unique_ptr temporary object returned by getOtherConsumer() would be
destroyed, which would cause the vector to point to a deleted object!
With this fixed, the plugin can be built with more recent versions of
clang.
Botond, I think you may be interested in this.  This patch fixes the crash that I was seeing when using the plugin on recent versions of clang!  With this fixed, I hope to be able to upgrade the clang versions we use for static analysis on the infrastructure to the ToT clang.  \o/
Blocks: 1123386
Comment on attachment 8629750 [details] [diff] [review]
Fix a startup crash when using the clang-plugin with clang>3.5

Review of attachment 8629750 [details] [diff] [review]:
-----------------------------------------------------------------

::: build/clang-plugin/clang-plugin.cpp
@@ +1199,5 @@
>  class MozCheckAction : public PluginASTAction {
>  public:
>    ASTConsumerPtr CreateASTConsumer(CompilerInstance &CI, StringRef fileName) override {
>  #if CLANG_VERSION_FULL >= 306
> +    std::unique_ptr<MozChecker> checker(llvm::make_unique<MozChecker>(CI));

Is there any particular reason for the addition of the llvm:: to make_unique? It's already in namespace, and seems unnecessary.

@@ -1206,2 @@
>      consumers.push_back(std::move(checker));
> -    consumers.push_back(checker->getOtherConsumer());

Isn't the problem that we were de-referencing checker after moving it into consumers here? The explanation in the commit message seems odd to me.

We could also fix this (I think) by just swapping the above two lines, but it's probably better to act the same as below.
Attachment #8629750 - Flags: review?(michael) → review+
(In reply to Michael Layzell [:mystor] from comment #3)
> ::: build/clang-plugin/clang-plugin.cpp
> @@ +1199,5 @@
> >  class MozCheckAction : public PluginASTAction {
> >  public:
> >    ASTConsumerPtr CreateASTConsumer(CompilerInstance &CI, StringRef fileName) override {
> >  #if CLANG_VERSION_FULL >= 306
> > +    std::unique_ptr<MozChecker> checker(llvm::make_unique<MozChecker>(CI));
> 
> Is there any particular reason for the addition of the llvm:: to
> make_unique? It's already in namespace, and seems unnecessary.

Just copying what LLVM consumers do, and a bit of C++14 safety.  :-)

> @@ -1206,2 @@
> >      consumers.push_back(std::move(checker));
> > -    consumers.push_back(checker->getOtherConsumer());
> 
> Isn't the problem that we were de-referencing checker after moving it into
> consumers here? The explanation in the commit message seems odd to me.
> 
> We could also fix this (I think) by just swapping the above two lines, but
> it's probably better to act the same as below.

You're right!  I will fix the commit message.
https://hg.mozilla.org/mozilla-central/rev/277e60059a10
Assignee: nobody → ehsan
Status: NEW → RESOLVED
Closed: 9 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla42
Product: Core → Firefox Build System
Product: Firefox Build System → Developer Infrastructure
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: