[PATCH] [Sema] Catch a case when 'volatile' qualifier is dropped while binding

Davide Italiano dccitaliano at gmail.com
Wed Jul 1 13:34:19 PDT 2015


Hi rsmith, rjmccall,

This is an attempt to fix https://llvm.org/bugs/show_bug.cgi?id=23882
Sema doesn't diagnose that binding 'volatile W' to to reference of type 'const W&' will discard qualifier and we end up in an infinite loop later on (until we run out of stack).

InitSequence::Perform() -> ... -> GatherArgumentsForCall() -> InitSequence::Perform()

I'm not sure if the check is OK as is, or needs to be generalized and/or moved.
I'll add the testcase in the PR if this review is accepted.

Thanks,

--
Davide

REPOSITORY
  rL LLVM

http://reviews.llvm.org/D10881

Files:
  lib/Sema/SemaInit.cpp

Index: lib/Sema/SemaInit.cpp
===================================================================
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -4087,6 +4087,12 @@
     = S.CompareReferenceRelationship(DeclLoc, cv1T1, cv2T2, DerivedToBase,
                                      ObjCConversion, ObjCLifetimeConversion);
 
+
+  if (isLValueRef && (!T1Quals.hasVolatile() && T2Quals.hasVolatile())) {
+    Sequence.SetFailed(InitializationSequence::FK_ReferenceInitDropsQualifiers);
+    return;
+  }
+
   // C++0x [dcl.init.ref]p5:
   //   A reference to type "cv1 T1" is initialized by an expression of type
   //   "cv2 T2" as follows:

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D10881.28894.patch
Type: text/x-patch
Size: 644 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150701/cf633b6c/attachment.bin>


More information about the cfe-commits mailing list