LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 12298 - clang segfaults with complicated constexpr code
Summary: clang segfaults with complicated constexpr code
Status: RESOLVED FIXED
Alias: None
Product: clang
Classification: Unclassified
Component: C++11 (show other bugs)
Version: trunk
Hardware: Macintosh MacOS X
: P normal
Assignee: Unassigned Clang Bugs
URL:
Keywords:
: 13085 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-03-18 09:55 PDT by jonathan.sauer
Modified: 2016-09-06 16:54 PDT (History)
6 users (show)

See Also:
Fixed By Commit(s):


Attachments
The (meta)program (27.32 KB, application/octet-stream)
2012-03-18 09:55 PDT, jonathan.sauer
Details
Log of gdb session with clang Debug+Assert (115.90 KB, application/zip)
2012-03-18 09:56 PDT, jonathan.sauer
Details

Note You need to log in before you can comment on or make changes to this bug.
Description jonathan.sauer 2012-03-18 09:55:29 PDT
Created attachment 8228 [details]
The (meta)program

clang r153011 segfaults without assertion when compiling the attached program using libc++ r152981.
Comment 1 jonathan.sauer 2012-03-18 09:56:27 PDT
Created attachment 8229 [details]
Log of gdb session with clang Debug+Assert
Comment 2 Richard Smith 2012-03-19 22:53:51 PDT
Smaller testcase:

struct S {
  template<typename T> constexpr static T f(T k) { return g(k); }
  template<typename T> constexpr static T g(T k) { return k ? f(k-1) : 0; }
};
constexpr int n = S().f(1);

While instantiating f, we mark g as referenced and try to instantiate it. While instantiating g, we mark f as referenced, don't notice we're already in the middle of instantiating it, and try to instantiate it again. We should accept this code, but should reject similar code where the mutually recursive calls between f and g occur in locations where a constant expression is required.
Comment 3 Richard Smith 2013-03-21 16:03:48 PDT
*** Bug 13085 has been marked as a duplicate of this bug. ***
Comment 4 Richard Smith 2016-08-30 21:15:34 PDT
Fixed in r280190.