classification
Title: Incorrect pointer alignment in _PyVectorcall_Function() of cpython/abstract.h
Type: compile error Stage: patch review
Components: C API Versions: Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: asn, eamanu, mcepl, python-dev
Priority: normal Keywords: patch

Created on 2020-03-24 06:58 by asn, last changed 2020-03-26 17:05 by mcepl.

Pull Requests
URL Status Linked Edit
PR 19133 open python-dev, 2020-03-24 06:59
PR 19179 closed mcepl, 2020-03-26 17:05
Messages (4)
msg364919 - (view) Author: Andreas Schneider (asn) * Date: 2020-03-24 06:58
In file included from /builds/cryptomilk/pam_wrapper/src/python/pypamtest.c:21:
In file included from /usr/include/python3.8/Python.h:147:
In file included from /usr/include/python3.8/abstract.h:837:
/usr/include/python3.8/cpython/abstract.h:91:11: error: cast from 'char *' to 'vectorcallfunc *' (aka 'struct _object *(**)(struct _object *, struct _object *const *, unsigned long, struct _object *)') increases required alignment from 1 to 8 [-Werror,-Wcast-align]
    ptr = (vectorcallfunc*)(((char *)callable) + offset);
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.


The correct way to do it would be:

union {
   char *data;
   vectorcallfunc *ptr;
} vc;

vc.data = (char *)callable + offset;
return *vc.ptr;
msg364954 - (view) Author: Emmanuel Arias (eamanu) * Date: 2020-03-24 17:34
Hi! I cannot reproduce the error. Could you provide the way to reproduce?

thanks
msg364963 - (view) Author: Andreas Schneider (asn) * Date: 2020-03-24 21:04
clang -Werror -Wcast-align ...

rpm -q clang9
clang9-9.0.1-8.1.x86_64

Does that help? Found in CI of

https://gitlab.com/cwrap/pam_wrapper
msg364977 - (view) Author: Andreas Schneider (asn) * Date: 2020-03-25 05:49
I forgot, for detecting alignment issues or strict aliasing and this also falls under strict aliasing, you need to turn on optimizations.

clang -O2 -Werror -Wcast-align ...
History
Date User Action Args
2020-03-26 17:05:29mceplsetnosy: + mcepl
pull_requests: + pull_request18539
2020-03-25 05:49:25asnsetmessages: + msg364977
2020-03-24 21:04:16asnsetmessages: + msg364963
2020-03-24 17:34:44eamanusetnosy: + eamanu
messages: + msg364954
2020-03-24 07:40:31asnsettype: compile error
versions: + Python 3.8
2020-03-24 06:59:55python-devsetkeywords: + patch
nosy: + python-dev

pull_requests: + pull_request18494
stage: patch review
2020-03-24 06:58:12asncreate