[PATCH] D17847: [SemaExprCXX] Avoid calling isInSystemHeader for invalid source locations

Pavel Labath via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 3 03:30:14 PST 2016


labath created this revision.
labath added a reviewer: nlewycky.
labath added subscribers: cfe-commits, lldb-commits.

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
"Loc.isValid()".

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.

http://reviews.llvm.org/D17847

Files:
  lib/Sema/SemaExprCXX.cpp

Index: lib/Sema/SemaExprCXX.cpp
===================================================================
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -1551,7 +1551,8 @@
   // 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)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17847.49725.patch
Type: text/x-patch
Size: 670 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160303/08f5f098/attachment-0001.bin>


More information about the cfe-commits mailing list