This is an archive of the discontinued LLVM Phabricator instance.

[FE] Manipulate the first byte of guard variable type in both load and store operation
ClosedPublic

Authored by Xiangling_L on Feb 1 2021, 2:17 PM.

Details

Summary

As Itanium ABI[http://itanium-cxx-abi.github.io/cxx-abi/abi.html#once-ctor] points out:

The size of the guard variable is 64 bits. The first byte (i.e. the byte at the address of the full variable) shall contain the value 0 prior to initialization of the associated variable, and 1 after initialization is complete.

We should manipulate the first byte of guard variable in both load and store operation in general cases.

Diff Detail

Event Timeline

Xiangling_L created this revision.Feb 1 2021, 2:17 PM
Xiangling_L requested review of this revision.Feb 1 2021, 2:17 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 1 2021, 2:17 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
clang/test/CodeGenCXX/aix-static-init-temp-spec-and-inline-var.cpp
193

Okay, so the store here is wrong, but it's got nothing to do with AIX.

The ABI doc (http://itanium-cxx-abi.github.io/cxx-abi/abi.html#once-ctor) says:

the first byte (i.e., the byte with lowest address)

So the bug here seems to be that the Itanium ABI implementation in Clang is incorrect for big-endian systems.

clang/test/CodeGenCXX/aix-static-init.cpp
144

What actually does the definition of _ZGVZN5test41fEvE11staticLocal look like? The test seems to be missing something pertinent for the change being proposed here. I will note that the symbol is 8-bytes (and aligned accordingly) from XL.

Xiangling_L marked 2 inline comments as done.Feb 2 2021, 11:29 AM
Xiangling_L added inline comments.
clang/test/CodeGenCXX/aix-static-init-temp-spec-and-inline-var.cpp
193

That makes sense to me. I will update the patch accordingly.

Xiangling_L marked an inline comment as done.

Align load and store operation related to guard variable by both using the first byte of the variable.

Xiangling_L retitled this revision from [FE][AIX] Use i8 as guard variable type in both load and store operation to [FE] Manipulate the first byte of guard variable type in both load and store operation.Feb 2 2021, 11:37 AM
Xiangling_L edited the summary of this revision. (Show Details)
clang/test/CodeGenCXX/global-init.cpp
84

nit: the lines above omit the end of the line. It's probably better to be consistent

guard.patch
1 ↗(On Diff #320864)

Looks like this file got added by accident.

Xiangling_L marked 2 inline comments as done.Feb 2 2021, 12:15 PM
Xiangling_L added inline comments.
clang/test/CodeGenCXX/global-init.cpp
84

It didn't omit the end of the line. It is because before my patch, there was no casting.

guard.patch
1 ↗(On Diff #320864)

Thanks!

clang/test/CodeGenCXX/global-init.cpp
84

Hi @Xiangling_L, I think Abhina meant the lines above in this file. The load has a bitcast too (and stops after the guard variable name).

Xiangling_L marked 2 inline comments as done.

Remove redundant file;

Xiangling_L marked an inline comment as done.

Addressed the comments related to test formatting;

clang/test/CodeGenCXX/global-init.cpp
84

I see. Sorry for the misunderstanding. @abhina.sreeskantharajan

This revision is now accepted and ready to land.Feb 2 2021, 12:45 PM

LGTM. I think there would be more concern if the load/store actions were previously symmetric, but this patch is actually needed for the symmetry. Nevertheless, please wait a bit before committing this (since this is a change for other platforms as well).