Page MenuHomePhabricator

AST: Address of dllimport variables isn't constant
ClosedPublic

Authored by majnemer on Jun 23 2014, 12:05 AM.

Details

Summary

The address of dllimport variables isn't something that can be
meaningfully used in a constexpr context and isn't suitable for
evaluation at load-time. They require loads from memory to properly
evaluate.

This fixes PR19955.

Diff Detail

Repository
rL LLVM

Event Timeline

majnemer updated this revision to Diff 10738.Jun 23 2014, 12:05 AM
majnemer retitled this revision from to AST: Address of dllimport variables isn't constant.
majnemer updated this object.
majnemer added reviewers: rnk, rsmith.
majnemer added a subscriber: Unknown Object (MLST).
rnk edited edge metadata.Jun 23 2014, 12:44 PM

Can you add a sema test for 'extern int __declspec(dllimport) y; constexpr int *x = &y;'?

lib/AST/ExprConstant.cpp
4395 ↗(On Diff #10738)

How is ZeroInitialization(E) different from Error(E)?

Sure, I'll add a SemaCXX test for that.

lib/AST/ExprConstant.cpp
4395 ↗(On Diff #10738)

It isn't other than being, in my opinion, less confusing. This isn't actually an error per-se because it isn't outright nonsense, it's just not evaluatable. This matches what the codebase does for:

int x = foo();

where x is at file scope and foo isn't constexpr.

majnemer updated this revision to Diff 10766.Jun 23 2014, 2:43 PM
majnemer edited edge metadata.
  • Add a SemaCXX test for constexpr + dllimport
rnk accepted this revision.Jun 23 2014, 3:36 PM
rnk edited edge metadata.

lgtm

This revision is now accepted and ready to land.Jun 23 2014, 3:36 PM
majnemer closed this revision.Jun 23 2014, 11:07 PM
majnemer updated this revision to Diff 10772.

Closed by commit rL211568 (authored by @majnemer).