@@ -285,15 +285,17 @@ pub fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
285285 // call. Despite that being "a const", it's not the kind of
286286 // const you can ask for the integer-value of, evidently. This
287287 // might be an LLVM bug, not sure. In any case, to work around
288- // this we drop down to the array-type level here and just ask
289- // how long the array-type itself is, ignoring the length we
290- // pulled out of the slice. This in turn only works because we
291- // picked out the original globalvar via const_deref and so can
292- // recover the array-size of the underlying array, and all this
293- // will hold together exactly as long as we _don't_ support
294- // const sub-slices (that is, slices that represent something
295- // other than a whole array). At that point we'll have more and
296- // uglier work to do here, but for now this should work.
288+ // this we obtain the initializer and count how many elements it
289+ // has, ignoring the length we pulled out of the slice. (Note
290+ // that the initializer might be a struct rather than an array,
291+ // if enums are involved.) This only works because we picked out
292+ // the original globalvar via const_deref and so can recover the
293+ // array-size of the underlying array (or the element count of
294+ // the underlying struct), and all this will hold together
295+ // exactly as long as we _don't_ support const sub-slices (that
296+ // is, slices that represent something other than a whole
297+ // array). At that point we'll have more and uglier work to do
298+ // here, but for now this should work.
297299 //
298300 // In the future, what we should be doing here is the
299301 // moral equivalent of:
@@ -305,7 +307,7 @@ pub fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
305307 // not want to consider sizeof() a constant expression
306308 // we can get the value (as a number) out of.
307309
308- let len = llvm:: LLVMGetArrayLength ( val_ty ( arr) ) as u64 ;
310+ let len = llvm:: LLVMGetNumOperands ( arr) as u64 ;
309311 let len = match ty:: get ( bt) . sty {
310312 ty:: ty_estr( * ) => { assert len > 0 ; len - 1 } ,
311313 _ => len
0 commit comments