r262700 - [SemaExprCXX] Avoid calling isInSystemHeader for invalid source locations

Pavel Labath via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 4 02:00:09 PST 2016

Author: labath
Date: Fri Mar  4 04:00:08 2016
New Revision: 262700

URL: http://llvm.org/viewvc/llvm-project?rev=262700&view=rev
[SemaExprCXX] Avoid calling isInSystemHeader for invalid source locations

While diagnosing a CXXNewExpr warning, we were calling isInSystemHeader(), which expect to be
called with a valid source location. This causes an assertion failure if the location is unknown.
A quick grep shows it's not without precedent to guard calls to the function with a

This fixes a test failure in LLDB, which always creates object with invalid source locations as it
does not (always) have access to the source.

Reviewers: nlewycky

Subscribers: lldb-commits, cfe-commits

Differential Revision: http://reviews.llvm.org/D17847


Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=262700&r1=262699&r2=262700&view=diff
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Fri Mar  4 04:00:08 2016
@@ -1551,7 +1551,8 @@ Sema::BuildCXXNew(SourceRange Range, boo
   // new.
   if (PlacementArgs.empty() && OperatorNew &&
       (OperatorNew->isImplicit() ||
-       getSourceManager().isInSystemHeader(OperatorNew->getLocStart()))) {
+       (OperatorNew->getLocStart().isValid() &&
+        getSourceManager().isInSystemHeader(OperatorNew->getLocStart())))) {
     if (unsigned Align = Context.getPreferredTypeAlign(AllocType.getTypePtr())){
       unsigned SuitableAlign = Context.getTargetInfo().getSuitableAlign();
       if (Align > SuitableAlign)

More information about the cfe-commits mailing list