Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfe2a16d

Browse files
committed
llvmjit: Work around bug in LLVM 3.9 causing crashes after7255943.
Unfortunately in LLVM 3.9 LLVMGetAttributeCountAtIndex(func, index)crashes when called with an index that has 0 attributes. Since there'sno way to work around this in the C API, add a small C++ wrapper doingso.The only reason this didn't fail before7255943 is that therealways are function attributes...Author: Andres Freund <andres@anarazel.de>Discussion:https://postgr.es/m/20201016001254.w2nfj7gd74jmb5in@alap3.anarazel.deBackpatch: 11-, like7255943
1 parent536de14 commitfe2a16d

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

‎src/backend/jit/llvm/llvmjit.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,14 @@ llvm_copy_attributes_at_index(LLVMValueRef v_from, LLVMValueRef v_to, uint32 ind
333333
intnum_attributes;
334334
LLVMAttributeRef*attrs;
335335

336-
num_attributes=LLVMGetAttributeCountAtIndex(v_from,index);
336+
num_attributes=LLVMGetAttributeCountAtIndexPG(v_from,index);
337+
338+
/*
339+
* Not just for efficiency: LLVM <= 3.9 crashes when
340+
* LLVMGetAttributesAtIndex() is called for an index with 0 attributes.
341+
*/
342+
if (num_attributes==0)
343+
return;
337344

338345
attrs=palloc(sizeof(LLVMAttributeRef)*num_attributes);
339346
LLVMGetAttributesAtIndex(v_from,index,attrs);

‎src/backend/jit/llvm/llvmjit_wrap.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ extern "C"
1616
#include"postgres.h"
1717
}
1818

19+
#include<llvm-c/Core.h>
20+
21+
/* Avoid macro clash with LLVM's C++ headers*/
22+
#undef Min
23+
24+
#include<llvm/IR/Attributes.h>
25+
#include<llvm/IR/Function.h>
1926
#include<llvm/MC/SubtargetFeature.h>
2027
#include<llvm/Support/Host.h>
2128

@@ -44,3 +51,28 @@ char *LLVMGetHostCPUFeatures(void) {
4451
returnstrdup(Features.getString().c_str());
4552
}
4653
#endif
54+
55+
/*
56+
* Like LLVM's LLVMGetAttributeCountAtIndex(), works around a bug in LLVM 3.9.
57+
*
58+
* In LLVM <= 3.9, LLVMGetAttributeCountAtIndex() segfaults if there are no
59+
* attributes at an index (fixed in LLVM commit ce9bb1097dc2).
60+
*/
61+
unsigned
62+
LLVMGetAttributeCountAtIndexPG(LLVMValueRef F, uint32 Idx)
63+
{
64+
/*
65+
* This is more expensive, so only do when using a problematic LLVM
66+
* version.
67+
*/
68+
#if LLVM_VERSION_MAJOR < 4
69+
if (!llvm::unwrap<llvm::Function>(F)->getAttributes().hasAttributes(Idx))
70+
return0;
71+
#endif
72+
73+
/*
74+
* There is no nice public API to determine the count nicely, so just
75+
* always fall back to LLVM's C API.
76+
*/
77+
returnLLVMGetAttributeCountAtIndex(F, Idx);
78+
}

‎src/include/jit/llvmjit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ extern char *LLVMGetHostCPUName(void);
129129
externchar*LLVMGetHostCPUFeatures(void);
130130
#endif
131131

132+
externunsignedLLVMGetAttributeCountAtIndexPG(LLVMValueRefF,uint32Idx);
133+
132134
#ifdef__cplusplus
133135
}/* extern "C" */
134136
#endif

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp