This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Fix clang-tidy crashes when using -fdelayed-template-parsing.
ClosedPublic

Authored by etienneb on Mar 16 2016, 10:57 PM.

Details

Summary

Fix crashes caused by deferencing null pointer when declarations parsing may be delayed.

The body of the declarations may be null.

The crashes were observed on a Windows build.

command-line switches: -fms-compatibility-version=19 -fms-compatibility

To reproduce them, run clang-tidy over the following basic file:

#include <string>
int main() {}

Templated functions that aren't used may contains a "null" body even if the decl->hasBody() is returning true.

template <typename T> void f() {}


FunctionTemplateDecl 0xd06340 <C:\src\llvm\examples\test.cc:1:1, col:34> col:28 f
|-TemplateTypeParmDecl 0xd061e8 <col:11, col:20> col:20 typename T
`-FunctionDecl 0xd062d0 <col:23, col:34> col:28 f 'void (void)'
  `-<<<NULL>>>

Diff Detail

Event Timeline

etienneb updated this revision to Diff 50910.Mar 16 2016, 10:57 PM
etienneb retitled this revision from to [clang-tidy] Fix clang-tidy crashes when using -fdelayed-template-parsing..
etienneb updated this object.
etienneb added reviewers: rnk, alexfh, emso, bkramer.
etienneb added a subscriber: cfe-commits.
aaron.ballman added inline comments.
cppcoreguidelines/ProTypeMemberInitCheck.cpp
183

Please do not use auto here since the type isn't spelled out in the initializer. (The line directly above it also should not be using auto either.)

modernize/RedundantVoidArgCheck.cpp
105–106

Don't use auto here either.

106

You could get rid of the if and else and just use it directly in removeVoidArgumentTokens().

removeVoidArgumentTokens(Result, SourceRange(Start, Body ? Body->getLocStart().getLocWithOffset(-1) : Function-getLocEnd()), "function definition");
etienneb updated this revision to Diff 50940.Mar 17 2016, 8:46 AM
etienneb marked 3 inline comments as done.

fixed. thanks.

aaron.ballman accepted this revision.Mar 17 2016, 9:29 AM
aaron.ballman added a reviewer: aaron.ballman.

LGTM, thank you!

This revision is now accepted and ready to land.Mar 17 2016, 9:29 AM
aaron.ballman requested changes to this revision.Mar 17 2016, 9:30 AM
aaron.ballman edited edge metadata.

Oops, I take that LGTM back. ;-) Almost LGTM -- this is missing test cases that exercise the behavior.

This revision now requires changes to proceed.Mar 17 2016, 9:30 AM
etienneb updated this revision to Diff 50971.Mar 17 2016, 1:13 PM
etienneb edited edge metadata.

tests added.

rnk accepted this revision.Mar 17 2016, 1:15 PM
rnk edited edge metadata.

lgtm, thanks!

aaron.ballman accepted this revision.Mar 17 2016, 1:17 PM
aaron.ballman edited edge metadata.

LGTM now (this time for sure), thank you!

This revision is now accepted and ready to land.Mar 17 2016, 1:17 PM
etienneb updated this object.Mar 17 2016, 8:39 PM
etienneb edited edge metadata.
aaron.ballman closed this revision.Mar 22 2016, 6:43 AM

Commit in r264049, thank you!