Add missing volatile qualifier. (#7570)

Variables being modified in the PG_TRY block and read in the PG_CATCH
block should be qualified with volatile.

The variable waitEventSet is modified in the PG_TRY block (line 1085)
and read in the PG_CATCH block (line 1095).

The variable relation is modified in the PG_TRY block (line 500) and
read in the PG_CATCH block (line 515).

Besides, the variable objectAddress doesn't need the volatile qualifier.

Ref: C99 7.13.2.1[^1],

> All accessible objects have values, and all other components of the
abstract machine have state, as of the time the longjmp function was
called, except that the values of objects of automatic storage duration
that are local to the function containing the invocation of the
corresponding setjmp macro that do not have volatile-qualified type and
have been changed between the setjmp invocation and longjmp call are
indeterminate.

[^1]: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf

DESCRIPTION: Correctly mark some variables as volatile

---------

Co-authored-by: Hong Yi <zouzou0208@gmail.com>
(cherry picked from commit ada3ba2507)
pull/7583/head
Xing Guo 2024-04-16 21:29:14 +08:00 committed by Jelte Fennema-Nio
parent cb1058192a
commit 67ee498d38
2 changed files with 13 additions and 4 deletions

View File

@ -883,7 +883,7 @@ WaitForAllConnections(List *connectionList, bool raiseInterrupts)
palloc(totalConnectionCount * sizeof(MultiConnection *)); palloc(totalConnectionCount * sizeof(MultiConnection *));
WaitEvent *events = palloc(totalConnectionCount * sizeof(WaitEvent)); WaitEvent *events = palloc(totalConnectionCount * sizeof(WaitEvent));
bool *connectionReady = palloc(totalConnectionCount * sizeof(bool)); bool *connectionReady = palloc(totalConnectionCount * sizeof(bool));
WaitEventSet *waitEventSet = NULL; WaitEventSet *volatile waitEventSet = NULL;
/* convert connection list to an array such that we can move items around */ /* convert connection list to an array such that we can move items around */
MultiConnection *connectionItem = NULL; MultiConnection *connectionItem = NULL;

View File

@ -465,8 +465,8 @@ static bool
AnyObjectViolatesOwnership(DropStmt *dropStmt) AnyObjectViolatesOwnership(DropStmt *dropStmt)
{ {
bool hasOwnershipViolation = false; bool hasOwnershipViolation = false;
volatile ObjectAddress objectAddress = { 0 }; ObjectAddress objectAddress = { 0 };
Relation relation = NULL; volatile Relation relation = NULL;
ObjectType objectType = dropStmt->removeType; ObjectType objectType = dropStmt->removeType;
bool missingOk = dropStmt->missing_ok; bool missingOk = dropStmt->missing_ok;
@ -480,8 +480,17 @@ AnyObjectViolatesOwnership(DropStmt *dropStmt)
Node *object = NULL; Node *object = NULL;
foreach_ptr(object, dropStmt->objects) foreach_ptr(object, dropStmt->objects)
{ {
Relation rel = NULL;
objectAddress = get_object_address(objectType, object, objectAddress = get_object_address(objectType, object,
&relation, AccessShareLock, missingOk); &rel, AccessShareLock, missingOk);
/*
* The object relation is qualified with volatile and its value is obtained from
* get_object_address(). Unless we can qualify the corresponding parameter of
* get_object_address() with volatile (this is a function defined in PostgreSQL),
* we cannot get rid of this assignment.
*/
relation = rel;
if (OidIsValid(objectAddress.objectId)) if (OidIsValid(objectAddress.objectId))
{ {