This is an archive of the discontinued LLVM Phabricator instance.

[CodeGen] Always use string computed in Sema for PredefinedExpr
ClosedPublic

Authored by efriedma on Jan 16 2019, 5:48 PM.

Details

Summary

We can't use any other string, anyway, because its type wouldn't match the type of the PredefinedExpr.

With this change, we don't compute a "nice" name for the __func__ global when it's used in the initializer for a constant. This doesn't seem like a great loss, so I'm not sure it's worth fixing. We would either need to store more information in the AST, or somehow make constant evaluation keep track of the parent function of the PredefinedExpr.

This could change behavior in some situations involving BlockDecl. Currently, CodeGenFunction::EmitPredefinedLValue has some logic to intentionally emit a string different from what Sema computed. Specifically, it does two things: one, it appends numbers to the string if there are multiple block expressions in the function that use __func__, and two, it rewrites __func__ for blocks in the initializer for a global variable. This code skips that logic... but changing the string in CodeGen is fundamentally broken anyway. (For example, sizeof(__func__) returns the wrong result.) Hopefully this doesn't affect practical code.

Fixes https://bugs.llvm.org/show_bug.cgi?id=40313 .

Diff Detail

Repository
rL LLVM

Event Timeline

efriedma created this revision.Jan 16 2019, 5:48 PM
efriedma edited the summary of this revision. (Show Details)Jan 16 2019, 5:50 PM

I agree that this is the right thing to do. If we want to make those improvements, they're doable within Sema.

rjmccall accepted this revision.Jan 16 2019, 9:27 PM
This revision is now accepted and ready to land.Jan 16 2019, 9:27 PM
This revision was automatically updated to reflect the committed changes.